0

Is there any way of getting only the int part of a number after division?

e.g. 3/2 = 1.5. how to get only 1 as the answer?

2nd May 2017, 5:55 PM
gaurav
gaurav - avatar
4 ответов
+ 3
The arithmetic operators between primitive number data types return the type of the one with highest precision. So if you have 3 / 2 the answer is 1 because an int divided by an int gives an int. If you have 3.0 / 2 the answer is 1.5 because of the highest precision and if you want to get the int value of it, you just cast it to int, like so int(3.0 / 2) or (int)(3.0 / 2) sorry, didnt saw the php tag.
2nd May 2017, 6:09 PM
Bebida Roja
Bebida Roja - avatar
+ 3
yes you can int a = 5; int b = 3 int c = a/b; "c will produce 1 as the result"
3rd May 2017, 1:05 AM
Krishneel Nair
Krishneel Nair - avatar
0
convert to string. cut out your int xD
2nd May 2017, 7:48 PM
Drauchris
Drauchris - avatar
0
Yes, there probably is a way.
13th May 2017, 2:50 PM
Joshua Koter
Joshua Koter - avatar