-1

Not to print, I want the actual value with less precision. For example if I say:

numb = 1.23456789123456789
print "num %0.2f" % numb

then it'll display it as having only 2 decimal places

num 1.23

but in reality the value for numb will remain the same. How do I convert numb so that it will actually have the value of 1.23?

The purpose is that I'm trying to send this value into an api and the value is too precise for the api which is causing an error, the only things I can find online are about displaying a less precise value but not actually changing the value.

Edit: I wanted to clarify that I want it rounded down. I know math.floor would do that but it only rounds to integers. Is there a function that rounds down but with decimals as well?

Note: I'm new to Python so code samples are preferred, thanks!

CookieMonster
  • 492
  • 6
  • 18

1 Answers1

1

Take a look at built-in function round()

numb = 1.23456789123456789
numb = round(numb, 2)
Ido Kadosh
  • 81
  • 8