Skip to main content

Search

Numbers with fixed decimal places

Comments

2 comments

  • AndrewBerezovskyy2

    Hello Senad Omicevic

     

    I prepared solution for you.

    On your form where you want have numbers without decimal place please create Form Load Action

    with type Execute Script and add this script:

     var oldLocaleFormatFunc = Number.prototype.localeFormat;
    var defaultNumberDecimalDigitsValue = Sys.CultureInfo.CurrentCulture.numberFormat.NumberDecimalDigits;
    Number.prototype.localeFormat = function(){     
         var numberValue = this;
         var hasNumberValueDecimalPart = numberValue % 1 != 0;     
         if(!hasNumberValueDecimalPart){
              Sys.CultureInfo.CurrentCulture.numberFormat.NumberDecimalDigits = 0;
              var localizedValue = oldLocaleFormatFunc.apply(numberValue,arguments);
              Sys.CultureInfo.CurrentCulture.numberFormat.NumberDecimalDigits = defaultNumberDecimalDigitsValue;
              return localizedValue;
           } 
         return oldLocaleFormatFunc.apply(numberValue,arguments);
    }

     

    In runtime if you will insert number with decimal part like 5.6 or 5.653  it'll be rounded to 5.60 or 5.65 and according to your regional settings. But if you will insert number without decimals like 6 it will not be rounded.

     

    Kind Regards
    Andriy Berezovsky

    0
  • Senad

    Hi Andriy,

     

    Thank you, this is working great.

    0

Please sign in to leave a comment.