How to format & print floating point numbers in Java with leading zeros? -
this question has answer here:
- how can pad integers zeros on left? 12 answers
for example: 23.7748884 , 344.456445 numbers working with. looking output format "000.0000". desired result 023.7749 , 344.4564. tried:
string.format("%.4f", 23.7748884) // output: 23.7749, not ok! desired: 023.7749 string.format("%.4f", 344.456445) // output 344.4564, ok!
you reach such result using like:
string.format("%08.4f", 23.7748884); // results 023.7749 string.format("%08.4f", 344.456445); // results 344.4564
Comments
Post a Comment