AskSharma
AskSharma

Reputation: 187

How to get decimal value on jsp without rounding

I am getting Big Decimal value 706.680988 on controller, which i am passing on jsp and displaying only 3 decimal point. i want to get value 706.680 on front end but it round up the value to 706.681. Please let me know how to get exact value on jsp without rounding it.

code below on jsp using formatNumber jstl tag, where myTotal is 706.680988

<fmt:formatNumber type="number" value="${myTotal}" groupingUsed="false" maxFractionDigits="3" />

Is their any other jstl tag which we can use here. please provide solution with code snippet. Thanks

Upvotes: 0

Views: 2929

Answers (2)

Anand Rajagopal
Anand Rajagopal

Reputation: 1633

you can use it below example

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

<fmt:formatNumber value="${foo}" pattern="0.0000"/>

Upvotes: 0

Scary Wombat
Scary Wombat

Reputation: 44813

using

<fmt:formatNumber value="${Value}" maxFractionDigits="3"/>

It is almost equivalent to Math.round, but not quite. Math.round method always rounds a .5 up to the nearest whole number. The number formatter uses the ROUND_EVEN approach, meaning if it is rounding .5, it will round to the nearest EVEN number (may be up or down)

see How do I round a number in JSTL?

Upvotes: 1

Related Questions