0

I want to round a variable to two decimal places using jstl.

for Example, value=3.005 ==> 3.01 value=1.076 ==> 1.08

<c:set var="testAmt"><fmt:formatNumber type="number" pattern="#########.00" groupingUsed="false" value="${3.005}" /></c:set>

This way I get testAmt = 3.00.

but if value is ${3.015} testAmt = 3.02

so, I converted it by doing the following:

<c:set var="testAmt"><fmt:formatNumber type="number" minFractionDigits="2" maxFractionDigits="2" value="${3.005}" /></c:set>

but it doesn't seem to be rounding properly only when variable contains zero after decimal.

value="${3.005} ==> 3.00 value="${3.015} ==> 3.02

why formatNumber doesn't round 3.005 to 3.01? How can i do this using JSTL ?

danB
  • 1
  • 1

0 Answers0