Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# Question on NumberFormat

Higgledy Smith
Ranch Hand
Posts: 192
I did not see a question posted like this one but found many similar, so I thought I'd post and ask.

This is from problem #13, Chapter 6 - from the K&B SCJP 6.0 book

My question is: Why is the output from nf.format(d) = 987.12346 and not 987.123456?

Thank you.

Higgledy

My output is:
format 987.12346
parse 987.123456

Here is my code:

Ankit Garg
Sheriff
Posts: 9543
33
Well it is clearly written in the K&B book that a maximum limit on the number of fractional digits only applies to formatting and not parsing...

Cristian Senchiu
Ranch Hand
Posts: 40
Higgledy Smith wrote:
My question is: Why is the output from nf.format(d) = 987.12346 and not 987.123456?

You set maximum of fraction digits to 5, so format() will show only 5 digits after point by rounding.
(The digits in your example are chosen to make it confusing ... looks like 5 is disappearing ... )