I am wondering how to truncate numbers in Python 3? For example, 87.28197 to 87.281
The standard in Python 2 was using % but this is no longer used.
I am wondering how to truncate numbers in Python 3? For example, 87.28197 to
Share
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.
The
%string formatter still is available in Python 3. It is preferred you use the''.format()string formatting syntax, which also supports specifying float precisions.Both of these work:
If it is just the one float you are converting to a string, then the
format()function is probably more convenient as you do not need to use a{0:..}placeholder: