I know how to control the number of decimals, but how do I control the number of zeros specifically?
For example:
104.06250000 -> 104.0625
119.00000 -> 119.0
72.000000 -> 72.0
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t think there is a pre-defined format for this – format in python are inherited from C, and I am pretty sure you don’t have the desired format in C.
Now, in python 3, you have the format special function, where you can do your own formatting. Removing the last zeros in python is very easy: just use the strip method:
If you want to keep a 0 after the decimal point, that’s not very difficult either.