0
Isnt 15/4 = 3.75? But why is this answer 3
3 Answers
+ 5
There is a datatype int (integer) and a datatype float (number with decimals).
If you divide an integer by an integer, the result will again be an integer.
So basically, the .75 gets dropped.
0
public class Program {
public static void main(String...hn) {
System.out.println(15/4); // by default if you divided integer with integer it will remove digit after comma
System.out.println(15/4.0); // if you supposed to get decimal number, simply just add comma followed by number what ever you want
System.out.println((double)15/4); // this is another way to get decimal number as result' it called type casting'
// cmmiw, cheers '
}
}
0
which language? Python makes this true 15/4 is converted to a float. Other languages depends on specific implementation. C, Pascal maintain type (int/int=int) javascript, doesn't truncates, so you'll get your 3.75