Adding two dollars amount in JSTL

Clash Royale CLAN TAG#URR8PPP
Adding two dollars amount in JSTL
My goal is make a variable called
"Dollar Diff" = Value of posting.dollarsInHeader -posting.dollarsReceived)/1000000
Check code below
<c:choose>
<c:when test="$ posting.dollarsReceived != 0">
<td class="alignright" class="$">
<fmt:formatNumber type="currency" minFractionDigits="1"
maxFractionDigits="1">$(posting.dollarsInHeader - posting.dollarsReceived)/1000000
</td>
</c:when>
<c:otherwise>
<td style="text-align: right; padding-right: 10px;">-</td>
</c:otherwise>
</c:choose>
Instead of $(posting.dollarsInHeader - posting.dollarsReceived)/1000000, I want to write $dollarDiff
$(posting.dollarsInHeader - posting.dollarsReceived)/1000000
$dollarDiff
1 Answer
1
I wouldn't recommend such logic written in view layer (jsp).
You can add a field in your posting class and write return the value accordingly.
//Ommit Posting class declaration
public double getDollarDiff()
return (this.dollarsInHeader-this.dollarsReceived)/1000000;
Then simply reference it with:
$posting.dollarDiff
EL treat your method as a field if it follow getter convention.
However, if you don't want to modify your pojo, you could try use
<c:set scope="request" var="dollarDiff" value="$(posting.dollarsInHeader - posting.dollarsReceived)/1000000"></c:set>
Then reference it with:
<c:out value="$requestScope.dollarDiff"></c:out>
<!--or-->
$requestScope.dollarDiff
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.