I use formatter for my double values in Java like:
private static final NumberFormat 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}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With