+ 1

Alguien me puede decir un código para redondear flotantes

31st May 2018, 1:59 PM
Starling
Starling - avatar
8 ответов
0
x= round (4.517, 0) f=(int(x)) print (f) y=round (4.137, 0) d=(int(y)) print (d) I got it, thanks for the help
31st May 2018, 10:19 PM
Starling
Starling - avatar
+ 2
Python has a function called, round round (0.6555, 2) will yield 0.66
31st May 2018, 4:20 PM
Mpho Mphego
Mpho Mphego - avatar
+ 2
round(3.14159, 2) == 3.14 int(3.14) == 3
31st May 2018, 9:36 PM
Pedro Demingos
Pedro Demingos - avatar
0
translate to English, might help
31st May 2018, 2:26 PM
Mpho Mphego
Mpho Mphego - avatar
0
can someone tell me a code to round floating numbers
31st May 2018, 3:41 PM
Starling
Starling - avatar
0
I hope that answers your question
31st May 2018, 4:20 PM
Mpho Mphego
Mpho Mphego - avatar
0
what I want is if number is 0.5 up add 1 to it add if it is 0.4 below it will leave it the same example 4.5 =5 and 4.4= 4
31st May 2018, 9:59 PM
Starling
Starling - avatar
0
To make matters worse or for simplicity, you can use numpy. In [1]: import numpy as np In [2]: x = 4.455 In [3]: np.ceil(x) Out[3]: 5.0 In [4]: np.floor(x) Out[4]: 4.0 Hope that helps.
1st Jun 2018, 7:13 AM
Mpho Mphego
Mpho Mphego - avatar