I\'m looking for a way to convert numbers to string format, dropping any redundant \'.0\'
The input data is a mix of floats and strings. Desired output:
0
I was dealing with a value from a json dictionary (returned by an API). All the above didnt help me so i constructed by own helper function. It truncates all the trailing zeros.
I Hope it helps someone out there
def remove_zeros(num):
nums = list(num)
indexes = (list(reversed(range(len(nums)))))
for i in indexes:
if nums[i] == '0':
del nums[-1]
else:
break
return "".join(nums)
num = "0.000000363000"
print(remove_zeros(num))
prints :
0.000000363