I have a bunch of numbers that are in string format,I would like some ideas on a function to format these.
ex.
input 00000000.00 – should output 0.00
input 00000123.00 – should output 123.00
input 0000-123.00 – should output -123.00
input 00-00123.45 – should output -123.45
input -0000123.00 – should output -123.00
input 00000000.-5 – should output -0.05
input 0000000-.25 – should output -0.25
one soultion that I can think for strings containing negative sign is as follows
ex.
num = “0000-123.00”
if num.find("-") != -1:
num = "-" + num.replace("-","")
this will give me num as -0000123.00 but I am not sure how to get rid of leading zeros.
You can parse the number like so:
then format it using Python’s string formatting,