JavaScript toFixed() does not work in number fields on Firefox

Published 05 Dec 2016 in Browsers, HTML & CSS, JavaScript & jQuery by ZigPress

Here’s a very short, quick post, detailing a Firefox scripting frustration that I discovered today.

Let’s say you have a JavaScript function that calculates a value. The value represents a monetary amount, so at the end of the function you would use

return my_value.toFixed(2);

to make sure that the “cents” or “pence” part of the amount is not chopped off, even if zero. In other words, the “toFixed” method converts something like “4” to “4.00” – as long as the value is numeric of course.

Now let’s say that you want to place the value into an HTML5 “number” input so the user can edit it if they want. No problem, assuming you have jQuery available you would use something like:


and the input element would be marked up something like this:

<input type=”number” step=”0.01″ name=”my_input” id=”my_input” />

Taking the earlier example, if my_value is “4.00”, you would expect “4.00” to show in the input, right?


Firefox will always chop off non-significant zeroes when populating a number field via JavaScript. In this example you would simply see “4” in the input.

The only solution is to change the field type from “number” to “text” – and lose the little up/down arrows in the process. There’s no other way around it. Like I said at the start of this post, very frustrating.

Hopefully this post will prevent someone wasting an hour on this problem, like I did.


  1. On 02 Jan 2017 at 03:29, Dipak Patil said:

    To avoid such problems i usually refer google chrome.

  2. On 05 Jan 2017 at 19:28, Simon said:

    Great post! Although Mozilla is a great browser but recently it is not coming up with impressive new features like it did years back. Now days chrome has taken its place!

  3. On 06 Jan 2017 at 16:32, Mike Schmidt said:

    Great post! Thanks so much, I was looking for some info on this and it was very helpful. Keep up the good work!

  4. On 20 Jan 2017 at 09:23, Bazaar Mantra said:

    Compatibility of Javascript with different browsers are one of biggest issue for the web developers.It is not just about a single function.Anyway you have explained it in a much better way.

Add a Comment

If you have used this form and would like a copy of the information held about you on this website, or would like the information deleted, please email