开发者

What is the equivalent of NumberFormat in JavaScript or JQuery?

开发者 https://www.devze.com 2023-02-14 14:58 出处:网络
I use formatter for my double values in Java like: private static final NumberForm开发者_JS百科at formatter = new DecimalFormat(\"###0.00\");

I use formatter for my double values in Java like:

private static final NumberForm开发者_JS百科at formatter = new DecimalFormat("###0.00");
formatter.format(doubleValue);

However I don't want to do it on the server side. How can I write an equivalent code in Javascript or JQuery?


Use the NumberFormatter plug-in for JQuery.

FYI: the old link was here.


I know this doesn't really answers your question, but have you thought of using the jstl formatNumber tag?


Use JSTL <fmt:formatNumber> ... http://www.tutorialspoint.com/jsp/jstl_format_formatnumber_tag.htm

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<fmt:formatNumber type="number" pattern="###0.00" value="${bean.value}" />


Trying using sprintf() for JavaScript.


Ext JS's Format class has a number function you can use to do this, see Ext.util.Format. As of Ext 4 it also supports locale-specific "thousand separators".

I guess the downside is that you need to import part of the Ext framework to use it!

0

精彩评论

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