0

I am defining my numberfield and then I amgetting some value like this

val = 3.555678

I am using decimalPrecision : 3 in my number field so The value is displaying is 3.556

I want my value should be display 3.555 so for that I am using

val = val.toFixed(3);

val is coming in consol 3.555 then numberfield.setValue(val); But in UI it is still comming 3.556

Why it is coming this.

Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
shanky singh
  • 1,121
  • 2
  • 12
  • 24

2 Answers2

1

I you want to display 3.555 you can do it in the following way

let val = 3.555678

let decimalPrecision = 3;

let roundedval = val.toFixed(3);

if(roundedval > val){
  val = roundedval - Math.pow(10, -1*decimalPrecision);
}

console.log(val);
marvel308
  • 10,288
  • 1
  • 21
  • 32
1

You can use:

var val=3.555678; 
val = Math.floor (val*1000)/1000;
console.log(val);
bocko
  • 388
  • 3
  • 7
  • 18