Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can JSTL fmt:formatNumber be used to get this output: "1 234.56"?

Tags:

jstl

I'm trying to get numbers formatted in this specific format:

"1 234.56"

So, two decimals, separated by a dot. And grouping thousands with a space char (optionally a single quote). The input values will never be larger than 9999.99.

I tried using patterns fo this, and even playing around with locales, but to no avail.

like image 971
Marc Diethelm Avatar asked Feb 26 '13 11:02

Marc Diethelm


1 Answers

Here is one way.

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="val" value="9999.99" /> 
<fmt:formatNumber value="${val}" pattern="#,###.##" var="pat" /> 
${fn:replace(pat, ",", " ")}
like image 52
rickz Avatar answered Nov 11 '22 01:11

rickz