0

How to round a number in python

Eg:4/3=0 and not 0. 66666.....

29th Jan 2020, 3:54 PM
Monish Gokulsing
10 Respostas
+ 5
if you want to round it accurately: round(4/3,(number of decimal places)) returns 1 if you want to round down: math.floor(4/3) returns 1 if you want to round up: math.ceil(4/3) returns 2 Note that you'll have to import math for the last two examples to work.
29th Jan 2020, 9:05 PM
Jannik Müller
Jannik Müller - avatar
+ 2
round(4/3, -1) round(4/3, 2) would round with 0.01 accuracy: 1.33 round(4/3, -2) would run with 100 accuracy: 0.0
29th Jan 2020, 4:08 PM
Seb TheS
Seb TheS - avatar
+ 1
Avinesh By rounding to 10s or higher.
29th Jan 2020, 4:16 PM
Seb TheS
Seb TheS - avatar
+ 1
Seb TheS oh may be it does. I'm no Python programmer, but just shared a little of what I know. 👍 I learnt something. But 0.666666... still does not seem like a possibility.
29th Jan 2020, 4:18 PM
Avinesh
Avinesh - avatar
+ 1
Thx guy hope you live a long and happy life
29th Jan 2020, 4:22 PM
Monish Gokulsing
+ 1
Jannik Müller 4/3 ~ 1.33333
29th Jan 2020, 9:10 PM
Seb TheS
Seb TheS - avatar
+ 1
Seb TheS I know. That's what happens when I do multiple things at once... Mistakes are corrected
29th Jan 2020, 9:13 PM
Jannik Müller
Jannik Müller - avatar
0
How would 4/3 will give 0. something? Hope this works too- x=int(4/3) print(x)
29th Jan 2020, 4:14 PM
Avinesh
Avinesh - avatar
0
Use //
31st Jan 2020, 2:53 PM
Huzaifa Khilawala
Huzaifa Khilawala - avatar
0
Wat
9th Feb 2020, 12:33 PM
Monish Gokulsing