Java Question

Print double with exact length in java

I could not find answer for my question on the net, so that's why I'm here.

I want to print a number with specified number of digits example in java:

Length = 10

1.123456789 ==> 1.123456789

123.123456789 ==> 123.1234567

123456.123456789 ==> 123456.1234

Answer

save the number as string and take the substring from 0 to 10. now you can parse it back and got the number with 10 digits