I'm doing some calculation with numbers and would like to only print an integer (the number without the decimals).
I thought that the toFixed()
method of the Number
class would do the trick, and it does most of the time. But quite frequently strange values are returned. Here are 2 examples:
Number(0.002).toFixed(0)
returns"0."
whileNumber(1.002).toFixed(0)
returns"1"
(without the period)Once in a while,
Number(0.002).toFixed(0)
returns"1"
Needless to say that's not the expected behaviour. Am I not using this method correctly?
*edit: *
I know I just have to do int(0.002)
to get 0
but I'd like to understand that strange behaviour.