What is equivalent to NumberFormat in JavaScript or jQuery?

I use a formatter for my double values โ€‹โ€‹in Java, for example:

private static final NumberFormat formatter = new DecimalFormat("###0.00"); formatter.format(doubleValue); 

However, I do not want to do this on the server side. How to write equivalent code in javascript or jquery?

+6
javascript jquery number-formatting
source share
5 answers

Use the NumberFormatter plugin for jQuery.

FYI: the old link was here .

+6
source share

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

+3
source share

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}" /> 
+1
source share
+1
source share

The Ext JS Format class has a number function that you can use for this, see Ext.util.Format . Starting with version 4, it also supports local โ€œthousands of delimitersโ€.

I assume the downside is that you need to import part of the Ext environment to use it!

0
source share

All Articles