+ 1

Float and interger

Example: number=1/3 print(number) Output: 0.3333333333333 Expect output: 1 So when there is a decimal, I want the number to add one without showing the decimal after it. How do I do that?

27th Jan 2021, 6:06 AM
Haha36
8 Antworten
+ 5
from math import ceil print(ceil(1/3)) # 1
27th Jan 2021, 6:11 AM
visph
visph - avatar
+ 3
I don't know if people here are downvoting for personal reasons but the code provided by Ashwini is also a correct answer.
28th Jan 2021, 1:39 AM
Sonic
Sonic - avatar
+ 2
Ashwini your code is also correct.
28th Jan 2021, 1:38 AM
Sonic
Sonic - avatar
+ 1
Thanks you
27th Jan 2021, 6:17 AM
Haha36
+ 1
Ashwini I tried your code, but I got 0 instead of 1.
27th Jan 2021, 6:21 AM
Haha36
27th Jan 2021, 8:55 AM
Ashwini Adsule
Ashwini Adsule - avatar
+ 1
Thank you, @Sonic sir.
28th Jan 2021, 3:02 AM
Ashwini Adsule
Ashwini Adsule - avatar
- 1
without using the library. Print(round(number+0.5))
27th Jan 2021, 6:18 AM
Ashwini Adsule
Ashwini Adsule - avatar