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
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);
}