Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• Liutauras Vilda
• Junilu Lacar
Sheriffs:
• Tim Cooke
• Jeanne Boyarsky
• Knute Snortum
Saloon Keepers:
• Stephan van Hulst
• Tim Moores
• Tim Holloway
• Carey Brown
• Piet Souris
Bartenders:
• salvin francis
• fred rosenberger
• Frits Walraven

# BigDecimal: divide round help

Ranch Hand
Posts: 218
Hello there,
I need an help using BigDecimal's API -
What I should get it'd always be an integer result up rounded.

So, if the division result is 0.12 or 1.99, it should be rounded up 1.00 or 2.00

So far, in a division like: new Double(0.78 .divide(15, 1, BigDecimal.ROUND_UP).doubleValue());
I get 0.1

How can I fix it?
[ October 23, 2006: Message edited by: Alessandro Ilardo ]

Ranch Hand
Posts: 2410
I don't see how you got output with that code.

Could you post the code you used?

Alessandro Ilardo
Ranch Hand
Posts: 218

from the logger:

Keith Lynn
Ranch Hand
Posts: 2410
What is the value of tempProdQuant?

Alessandro Ilardo
Ranch Hand
Posts: 218
15

Keith Lynn
Ranch Hand
Posts: 2410
So you're rounding 0.78/15 = 0.052 up to 0.1. The output sounds reasonable.

Alessandro Ilardo
Ranch Hand
Posts: 218
Yes, but as result I need an Integer which is rounded away from 0

So, if the division result is 0.12 or 1.99, it should be rounded up 1.00 or 2.00

Keith Lynn
Ranch Hand
Posts: 2410
I think you need to change the scale to 0 because that signifies how many digits there are after the decimal point.

Alessandro Ilardo
Ranch Hand
Posts: 218
You're right, Thank you very much for your help.

 Their achilles heel is the noogie! Give them noogies tiny ad! Two software engineers solve most of the world's problems in one K&R sized book https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton