toFixed() method has, for IE, probably a bug in it's implementation when dealing with small floated numbers.
Try this both in Moz and IE:
Code:
var x=0.09;
var y=0.099;
alert(x.toFixed(1));
alert(y.toFixed(1));
Moz will return correctly 0.1 for both numbers, while IE will return 0.0 for the first one.
So that, whenever is possible, avoid using toFixed() when you can use safer methods.
newatjava
Math.round() should work; if it does not as expected, in is not its fault, there must be another error somewhere else.
By the way, the code is old. You should use the crossbrowser getFullYear() method to avoid the Y2K "bug".
And don't use XHTML Doctype, unless you really need to handle/import XML files. Under XHTML DTD you must isolate the javascript embedded codes inside CDATA islands.
But I see no reason for not using only Math.round(). After all, that is exactly what that method does: rounds the floated number to an integer (no decimals, then)... What is the use of toFixed() in all these?
Bookmarks