How can I make a formatted output for a number (e.g. long
or BigDecimal
) in EL? For example, I want to limit a number of decimal digits to 3 in
${result.returnValue.contract.balance}
How can I make a formatted output for a number (e.g. long
or BigDecimal
) in EL? For example, I want to limit a number of decimal digits to 3 in
${result.returnValue.contract.balance}
Using <fmt:formatNumber/>
http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/fmt/formatNumber.html
For example:
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatNumber
value="${result.returnValue.contract.balance}"
maxFractionDigits="3"/>
The modern Java EE 5-8 approach with JSF is:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:outputText value="#{result.returnValue.contract.balance}">
<f:convertNumber minFractionDigits="3"/>
</h:outputText> ...
See also Using the Standard Converters. Since Java EE 6 (2009), JSF/Facelets is recommended.
© 2022 - 2024 — McMap. All rights reserved.