Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 3
    toFixed is quite buggy though. Also, here's a better link than w3schools developer.mozilla.org/en-US/docs/JavaScript/Reference/… Commented Aug 12, 2012 at 19:14
  • 162
    but toFixed() returns number as string, if you will compare numbers, you need to use parseFloat again. Commented Mar 27, 2013 at 12:14
  • 31
    Use var twoPlacedFloat = + parseFloat(yourString).toFixed(2) to convert to float Commented Jul 23, 2014 at 10:52
  • 17
    Add parens to get a number instead of string: parseFloat((yourString).toFixed(2)); Commented Nov 19, 2014 at 22:02
  • 3
    JavaScript does not have float data type by default. Check this developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures It has only number data type. So any attempt to covert number to floating value will actually converts number to string/number representation. So real life float value 2.00 is always string/number in javascript. Commented Apr 9, 2015 at 6:22