File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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