开发者

$.formatNumber jquery API problem in IE

I'm using a number formatter jquery library 开发者_如何学编程available here http://code.google.com/p/jquery-numberformatter/

I found a problem in IE while using this.

The following code

var number = "0.2343";
alert($.formatNumber(number, {format:"#,##0.00") );

returns 0.23 in firefox but .23 in IE Could anyone tell me how I can get 0.23 in both the cases please?

Thanks


parseFloat(number).toFixed(2).replace(".", ",")


I strongly recommend you to change your library to jQuery Globalization plug-in(It's will be a part of jQuery core in version 1.5+). For more information, you can visit at the following link in ScottGu's Blog.

jQuery Globalization Plugin from Microsoft


First of all, you're formatting from a String, not from a number (float or double). Try changing the declaration to:

var number = 0.2343; //this is a double

or, if you can't modify that String, parse it to a float or double:

var number = parseFloat("0.2343"); //this is a float

Then try changing your format string to ",##0.00". It works for me:

alert($.formatNumber(number, {format:",##0.00") );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜