SOLVED: How to round up a BigDecimal

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
2517
Joined: Aug 22 2008 - 2:05pm
Last seen: 10 years 1 month ago

2 Answers:

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
2517
Joined: Aug 22 2008 - 2:05pm
Last seen: 10 years 1 month ago

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: 6 years 6 months ago
Feedback