cancel
Showing results for 
Search instead for 
Did you mean: 

Rounding bigDecimals

Former Member
0 Kudos

Hi,

I'm using NW EP 7.0.

I prepared a web dynpro java application and called a RFC function.

RFC gets bigDecimal typed output value, i must round it.

I searched but i did not find the rounding bigDecimal in jdk 1.4 environment.

How can i do that?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Try this code to round the bigdecimal values.

BigDecimal aDecimal = new BigDecimal"0.195");

BigDecimal another = aDecimal.setScale(2,aDecimal.ROUND_HALF_DOWN);

System.out.println("bigd = "+aDecimal);

System.out.println("bigd1 = "+another);

Hope it helps.

Regards,

Gayathri

Answers (2)

Answers (2)

Former Member
0 Kudos

check this line

http://www.roseindia.net/java/java-bigdecimal/round.shtml

show the code to help rounding of the bigdecimal values

Former Member
0 Kudos

He asked explicitly for Java 1.4. BigDecimal round() was introduced in Java 1.5. So this wont help.

Stick to "scale", it does what you want.

Former Member
0 Kudos

check: http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigDecimal.html

What you need is to set a scale and provide a Rounding Method. Rounding methods are defined as constants (int) inside the BigDecimal class.

That should solve your problem

Jan