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.
5 ответов
+ 7
Do this 90 * 10 // 100
// is called floor division operator
+ 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)
+ 2
There are two direct ways. Either casting it to int:
value = int(x/y)
Or using floor division:
value = 10 // 9
0
Using floor division//
- 1
X=90*0.1