How do I force the display of a decimal in an ExtJS NumberField to a certain precision?

后端 未结 7 2383
梦谈多话
梦谈多话 2020-12-14 10:39

I have a form with a NumberField that gets values of type float from JSON. If the values happen to be whole numbers, then no decimal places are sho

相关标签:
7条回答
  • 2020-12-14 11:11

    if you want something like below:

    enter 50 > u got 50

    50.10 > 50.10

    50.123 > 50.12

    Try this:

    , setValue: function (v) {
          if ( !v || isNaN(v)) {
            v = '';
          }
          else if (v % 1 != 0) {    //means number is not whole number
            v = this.fixPrecision(String(v).replace(".", this.decimalSeparator));
          }
    
         return Ext.form.NumberField.superclass.setValue.call(this, v);
    }
    , fixPrecision: function (value) {
        if (!this.allowDecimals || this.decimalPrecision == -1) {
           return value;
        }
    
        return parseFloat(value).toFixed(this.decimalPrecision);
    }
    
    0 讨论(0)
提交回复
热议问题