Is there a good way to format a minus number with zero padding in Erlang? The following works well for unsigned value, but for minus value, zero is padded before the sign.
io:format("~4..0B~n", [42]).
0042
ok
io:format("~4..0B~n", [-42]).
0-42
ok
What I have in mind is the following format.
(ruby)
1.9.2-p290 :004 > sprintf("%05d", -42)
"-0042"
1.9.2-p290 :005 > sprintf("%05d", 42)
"00042"
(python)
>>> "%05d" % -42
'-0042'
>>> "%05d" % 42
'00042'
I've referred to the following questions, but haven't been able to find one which talks about minus values.
How to format a number with padding in Erlang
Erlang: How to transform a decimale into a Hex string filled with zeros