0
votes

in jstl currency for matter is using http://java.sun.com/jsp/jstl/fmt.

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

we are using as

<fmt:formatNumber maxFractionDigits="0" currencySymbol="$" type="currency" value="${employeeDetail.employee.annualSalary }" />


Now behavior is :

Ex: $470.161 is round to $470.16)
Ex: $470.165 is round to $470.16)
Ex: $470.166 is round to $470.17)

what is expected uis
Ex: $470.161 is round to $470.16)
Ex: $470.165 is round to $470.17)
Ex: $470.166 is round to $470.17)

is there is any way we can set round RoundingMode.HALF_UP ?

Any way to override the default behavior of [jstl fmt tag library] and giving support of rounding mode.

1

1 Answers

0
votes

Can you get the standard formatNumber tag to round the number differently? AFAIK, No.

But you could do one of the following:

  • You could change the value attribute to an expression that uses a function to round the value first; e.g. How to call a static method in JSP/EL?

  • You could create a custom Tag that extends the existing Tag class and does the rounding differently. The snag is:

    • The actual tag class (and its name) depends on the implementation of JSTL you are using. So your custom Tag class likewise will be tied to a specific JSTL implementation.

    • The existing tag class implementation may not be amenable to extension.