0

Is there a way to get rid of the decimal after dividing? If yes, how?

like in example i want to create a program to tell me how much a thing would cost with a 10% tax. Let's say i want to buy a printer which costs $90 without tax. The way to calculate 10% is by determining 1% (9 / 100 ; this is the problem) which is 0.9 and then multiplying it by 10 which is 9. I'll skip the last part but the thing is that when a python program divides it would show as 9.0; and i want to know how to rid of the 0.

12th Jun 2021, 3:40 PM
Ricinoob
Ricinoob - avatar
5 odpowiedzi
+ 7
Do this 90 * 10 // 100 // is called floor division operator
12th Jun 2021, 3:51 PM
Ore
Ore - avatar
+ 7
Richard Lévai , there are several ways of doing this: ( if just wanted to remove the fractional part of the number) x = int(10 / 9) # converting the float to int print(x) # or: # using integer (floor) division x = 10 // 9 print(x)
12th Jun 2021, 3:56 PM
Lothar
Lothar - avatar
+ 2
There are two direct ways. Either casting it to int: value = int(x/y) Or using floor division: value = 10 // 9
12th Jun 2021, 5:27 PM
TheAdeyemiOlayinka 💗
TheAdeyemiOlayinka 💗 - avatar
0
Using floor division//
13th Jun 2021, 6:42 PM
GAYATHIRI
GAYATHIRI - avatar
- 1
X=90*0.1
13th Jun 2021, 8:26 AM
Abhinandan Prasad