-2

Currently have the following javascript code:

div.html( Drupal.t("Date")+": "+d.date+"</br>"+Drupal.t("Value")+": " + (d.value))

Value that i'm getting is 0.1651859999999985 . I wanna round it off to the first four decimal numbers. Any help? I tried Math.ceil(d.value*10)/10) but it was only getting the first decimal :( Any help? I wanna get 0.1652

1 Answers1

0

Should be Math.ceil(d.value*10000)/10000 example:

console.log(Math.ceil(0.1683123*10000)/10000)
console.log(Math.ceil(823.124148336763*10000)/10000) // round up to the ceiling
console.log(Math.floor(823.124148336763*10000)/10000) // round down to the floor
console.log(Math.round(823.124148336763*10000)/10000) // below .5 -> down, above .5 -> up
BogdanBiv
  • 1,485
  • 1
  • 16
  • 33