View Full Version : Number.toFixed() does it convert number into string?
07-07-2011, 04: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, 07: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-07-2011, 08:41 PM
07-08-2011, 05: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, 07:07 PM
I get debuggers out of my nose every morning.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.