This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes NumberFormat Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "NumberFormat Problem" Watch "NumberFormat Problem" New topic
Author

NumberFormat Problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634




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


OCPJP 6.0 93%
OCPJWCD 5.0 98%
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Nov 04, 2009
Posts: 2066

Check your code again, because you're providing d to be format, but you supposed to format that String s instead. isn't it?


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NumberFormat Problem
 
Similar Threads
nit w/ chap.6 q.13 S&B
NumberFormat.format()
NuberFormat format and parse doubt
Confused with answers from (K&B) Chapter 6: Question 13
Question on NumberFormat