Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the variable to 2 decimal places

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.

like image 695
TheOnlyIdiot Avatar asked Dec 26 '12 03:12

TheOnlyIdiot


People also ask

How do you format a variable to two decimal places?

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.

How do I change value to 2 decimal places in Excel?

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.


2 Answers

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>
like image 133
Chaitanya Marathe Avatar answered Oct 16 '22 02:10

Chaitanya Marathe


<fmt:formatNumber var="formattedBillableTime" type="number" minFractionDigits="2" maxFractionDigits="2" value="${ps.computedAmount}" />

<c:set var="billableTime" value="${**formattedBillableTime**}" />
like image 32
zaaku Avatar answered Oct 16 '22 00:10

zaaku