Sunday, May 3, 2015

Method to round decimal no with given no. of positions using JQuery

 Round: function (x, y) {
        ///<summary>Method to round decimal no. to given no. of positions</summary>
        /// <param name="x" >
        ///     Input decimal value
        /// </param>
        ///<param name="y" >
        ///     No. of decimal points to be restricted
        /// </param>
        return Math.round(x * Math.pow(10, y)) / Math.pow(10, y);

        //return parseFloat(x).toFixed(y);
    },

  RoundTime: function (x, y) {
        ///<summary>Method to round decimal no. to given no. of positions</summary>
        /// <param name="x" >
        ///     Input decimal value
        /// </param>
        ///<param name="y" >
        ///     No. of decimal points to be restricted
        /// </param>

        var time = x;
        var timeArr = String(time).split('.');
        var hrs = timeArr[0];
        var min = 0;
        if (parseFloat(timeArr[1]) > 0) {
            min = 60 * parseFloat(timeArr[1]);
        }
        //var minArr = String(min).split('.');
        var convertmin = parseFloat(min) / 10000000000000000;
        if (parseFloat(convertmin) > 0) {
            if (parseFloat(convertmin) < 1) {
                return hrs + ".0" + ERPScriptUtils.Round(convertmin * 10, 0);
            }
            else {
                if (parseFloat(convertmin) < 10) {
                    return hrs + "." + ERPScriptUtils.Round(convertmin, 2) * 10;
                }
                else {
                    return hrs + "." + ERPScriptUtils.Round(convertmin, 2);
                }
            }
        }
        else {
            return hrs + ".00";
        }


    },

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...