• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

problem in round off

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to round off my values to 2 decimal points.
example:
my value 7.826, needed roundoff values 7.85 not as 7.83.i need java coding for these.thanks in advances
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how are you getting 7.85 from 7.826? what exactly are you requirements here? we can't tell if you're always rounding up, if you're rounding to the closes 1/20th (i.e. either .x5 or .x0) if you're rounding up at least .02 or something else.

Please provide more details on what you want.
 
bala manian
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my clients expecting round off value as 7.85, if he gets 7.826.what should i do for these?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If that is really what your client wants, then your client wants some strange, non-standard way of rounding numbers. As Fred already said, you have to find out first what rules for rounding your client wants exactly. We cannot guess here what your client wants. So, go and talk to them to find out exactly what they want.

Rounding 7.826 to 7.85 is not logical.
 
Smart Bear Support
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to generalize what your client wants. As Fred tried to explain, one specific example -- especially the one you gave -- is not enough to derive an appropriate rounding algorithm.

A further consideration is what is the type of the number that you are rounding and what is the purpose of the data? You may be needing an arbitrary precision decimal (java.math.BigDecimal) which you can round using many different rounding modes (java.math.RoundingMode).
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic