Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Division in java double variable.

Hi all

I have a simple query .I am using the following code in my java mapping.

Please follow the following java code

double d1 = 22058310.53;

System.out.println("Output Value = " + d1/1000);

This gives me an output

Output Value = 220583.10530000002

whereas the correct o/p should be 220583.1053

Can anyone pls provide a solution to get the correct result.


NIlesh Taunk.


Hi Nilesh,

Use the following code to Divide by 1000 using BigDecimal class which is better than using decimal type.

<b>BigDecimal num= new BigDecimal("22058310.53");

BigDecimal result= num.movePointLeft(3);

System.out.println("Output Value = " + result.toString());</b>


<b>BigDecimal num= new BigDecimal("22058310.53");

BigDecimal result= num.divide(num,BigDecimal.ROUND_HALF_UP);

System.out.println("Output Value = " + result.toString()); </b>

Hope this helps.



0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question