floating point - Leading zeros for float in Swift -
here float value:
5.3 23.67 0.23 and want them be
05.30 23.67 00.23 using string(format: "%.2f", floatvar) can make 2 digit following decimal point cannot add 0 before it.
i've tried string(format: "%04.2f", floatvar) suggest here display same %.2f
is there clean way of doing within swift standard libraries?
try this:
string(format: "%05.2f", floatchar) from this documentation: 0 means pad leading zero. 5 minimum width, including dot character.
Comments
Post a Comment