I have a number 10.039999999999 I want 2 decimals....
# suitescript
s
I have a number 10.039999999999 I want 2 decimals. What is the best way to get to 10.04 ?
n
parseFloat(yourNumber.toFixed(2))
👍 1
b
you should use something like expected-round if you dont want to be screwed by floating point rounding, especially when it comes to currency
other alternatives are to use format.format to format it as currency (it uses a rounding delta)
n
@battk do you mean we should avoid .toFixed ?
b
the standard example is to try
Copy code
parseFloat(1.005.toFixed(2))
😮 1
the fixed point math choice is BigNumber
s
I have all the example in the world for a date, but I don't have even one for number Can you send me one
b
format.format syntax is fairly usable if you know how to pick from currency from format.Type