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
• Bear Bibeault
• Liutauras Vilda
Sheriffs:
• Jeanne Boyarsky
• Tim Cooke
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Jj Roberts
• Carey Brown
Bartenders:
• salvin francis
• Frits Walraven
• Piet Souris

# Rounding decimal or Generic respect if Decimal, Centena, Milhar..

Greenhorn
Posts: 2
• Number of slices to send:
Optional 'thank-you' note:
Personally, I found the solution to a post that opened there a week ago, is working for all numbers below 9.00, typing eg 8.99 it calculates 9:00, another value it calculates 5.10 to 9.00, is a standard for stores, but the type 9.00 and 12, nine, nine should be the same, since the 12, would have to be 19.00, and there on. The following algorithm, if someone can help me thank you.

Kleber Gracia
Greenhorn
Posts: 2
• Number of slices to send:
Optional 'thank-you' note:
Good personal afternoon okay, I could decipher in parts, the rule for 9.00 and 19.00, but we lack the rest follows suit.

1.45 -> 9.00
5.90 -> 9.00
4.90 -> 9.00
9.00 -> 9.00
---------------
9.10 -> 19.00
18.47 -> 19.00
----------------

for it already calculates, now I need:
19.10 -> 29.00
25.47 -> 29.00
29.10 -> 39.00

and there forward.

The following code done to 9:19 missing a generic that does everything.

Tks

author
Posts: 23893
142
• Number of slices to send:
Optional 'thank-you' note:
Wow. That is a lot of code for a straightforward mathematical operation. I was able to get it down to four big decimal method calls chained together. The four operations were...

1. Add one to get it to the nearest whole tens digit (so that it can be rounded as a tens digit, instead of rounded as "around the nine").
2. Divide by ten, zero scale, round up, in order to get rid of the unwanted digits.
3. Multiply by ten, to get it back into the tens digit.
4. Subtract one to undo step one.

And this will work for every case that you listed.

Henry