Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NumberFormat Problem

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



output:


987.12346



i think
System.out.println(nf.format(d) + " ");


should give 987.12345 as the output
since
nf.setMaximumFractionDigits(5);

rounds off "987.123449" to "987.12345"

am i wrong please check

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mohitkumar gupta wrote:
i think
System.out.println(nf.format(d) + " ");


should give 987.12345 as the output
since
nf.setMaximumFractionDigits(5);

rounds off "987.123449" to "987.12345"

am i wrong please check



but I don't see d as 987.123449, but rather as 987.123456, and it is being rounded off correctly.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check your code again, because you're providing d to be format, but you supposed to format that String s instead. isn't it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic