• 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

DecimalFormat not rounding with HALF_EVEN mode

 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The ouput is 500. It means it just simply truncates the digits after decimal. How do I use the Decimal pattern like
"###0;-###0" to indicate it has no decimal but maintain an half-even rounding mode ? I read the DecimalFormat API and it says its default rounding mode is half-even. But it seems this rounding is not applied here.

Please help.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raj Ohadi wrote:I read the DecimalFormat API and it says its default rounding mode is half-even.


I'm an old printf() fan (String.format() works the same way BTW), and with that you'd use:but I can't help much with DecimalFormat because I'm no expert. I suspect it has far more options; with printf()/String.format() you have to accept its default rounding (whatever that is; probably half-even too).

Winston
 
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote: . . its default rounding (whatever that is; probably half-even too).

Winston

I think it’s half away from zero, but I’m not certain.
 
Campbell Ritchie
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have checked in the Formatter class; for %e it says[quot]ethe value will be rounded using the round half up algorithm.
 
Always! Wait. Never. Shut up. Look at this 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