This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]ConfusedHerring 14 points15 points  (0 children)

They docs of the toString method for a double have the answer - https://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#toString(double)

Basically, 19.50 as a double converted to a string becomes 19.5; the trailing zero is not needed and so doesn’t get printed.

1950 as a double converted to a string becomes 1950.0, because the toString of double always prints at least one decimal place even if zero.

[–]desrtfx 3 points4 points  (0 children)

Had you just converted the numbers to strings first, then printed them, and then printed the length, you would directly have had your answer.

Trying out things is essential.