07-07-2011, 05:07 PM
When I used toFixed() method on a number, I thought that this method round a number to a specified approximation, but I got a surprising result, the number became string!
15.23689.toFixed(2) ==> "15.24"
So does it convert the number into string?
07-07-2011, 08:22 PM
It returns a string representing the number after rounding, which is useful for representation purposes without losing the original value. It has no effect upon the number.
One way to get a number type to hold the rounded number: var n = Number( 15.23689.toFixed(2) );
07-08-2011, 06:22 PM
an even simpler coercion:
That's a good one :) But most of the time I prefer Number(). It is more intuitive for other coders from the team which might need to analyze or change the codes. The easiness of debugging, you know ... :)
07-08-2011, 08:07 PM
I get debuggers out of my nose every morning.