SOLVED: How to round up a BigDecimal

3

Hi,

I want a value of 3.665 to be rounded to 3.67.

I have a field provided with a BigDecimal. The field is in a crosstab. I've set the field to show 2 decimal places. The problem I am having is that it doesn't seem to round correctly.

In the fields textfield I have:

$V{gpaAverageMeasure}.setScale(2, java.math.RoundingMode.HALF_UP)

Instead of rounding up to 3.67 it rounds down to 3.66.

Any help would be very welcome!

Magnus

 



Post Edited by phantastes at 03/23/2010 21:02



Post Edited by phantastes at 03/23/2010 22:46
phantastes's picture
Joined: Aug 22 2008 - 2:05pm
Last seen: 5 years 10 months ago

2 Answers:

3

The above $V{gpaAverageMeasure}.setScale(2, java.math.RoundingMode.HALF_UP) , were $V{gpaAverageMeasure} is a BigDecimal, works.

I had pulled in floatValue() in the measure calculation which messed it up. So the short of it is, just use BigDecimal.

Magnus

phantastes's picture
Joined: Aug 22 2008 - 2:05pm
Last seen: 5 years 10 months ago
0

Magnus how you solved it ? I have the same error.

But I use $F{FOB75}.setScale(2,BigDecimal. ROUND_HALF_UP).multiply($F{QRV075}.setScale(2,BigDecimal. ROUND_HALF_UP))   Where $F{FOB75} and $F{QRV075} are a bigDecimal field.

 

Any idea how to do that right.

Thank you,

EstebanR

estebanretana's picture
Joined: Jul 10 2015 - 12:42pm
Last seen: 2 years 3 months ago
Feedback
randomness