logo-MindMajix
PostPythonPython
j
jordan chris

Posted on 19th July 2024|58 views

0
votes

Print Float With 2 Decimals Python

Is there any way to limit the floats to two decimals?

I want x to round to 14.98

>>>x

14.97999999999

To do so, I have tried doing this

>>> round(x, 2)

14.97999999999

This round function did not work for me. Can anyone help me?

 

1 answers
Answers
P
sumana reddy

Posted on 19th July 2024| views

If you are using round(x, 2), this may give

14.97999999999

So try this 

print("%.2f” % round(a, 2) this will give

14.98 as the output

  

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo

  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos
Name
Course *
Email *
Phone Number