• Post Reply Bookmark Topic Watch Topic
  • New Topic
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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic