I'm creating a variable in JSTL
using
<c:set var="billableTime" value="${ps.computedAmount}" />
My problem is ps.computedAmount
is not a 2-digit decimal and I want the ps.computedAmount
to be rounded off to 2-decimals before assigning to billableTime
. I know how to display a 2-digit number in JSTL
by using
<fmt:formatNumber type="number" minFractionDigits="2" maxFractionDigits="2" value="${ps.computedAmount}" />
But my problem is about assigning a 2-digit value to a JSTL
variable.
Just use %. 2f as the format specifier. This will make the Java printf format a double to two decimal places. /* Code example to print a double to two decimal places with Java printf */ System.
By using a button: Select the cells that you want to format. On the Home tab, click Increase Decimal or Decrease Decimal to show more or fewer digits after the decimal point.
I think you can do it like this:
<c:set var="billableTime"><fmt:formatNumber type="number" minFractionDigits="2" maxFractionDigits="2" value="${ps.computedAmount}" /></c:set>
<fmt:formatNumber var="formattedBillableTime" type="number" minFractionDigits="2" maxFractionDigits="2" value="${ps.computedAmount}" />
<c:set var="billableTime" value="${**formattedBillableTime**}" />
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