Hi,
I have 2 codes below which is almost the same but with difference answer.
Anyone can explain?
score = 1.8PHP Code:double score;
score = 9.00 / 5
vs
score =1PHP Code:double score;
score = 9 / 5
thanks,
Popskie
Printable View
Hi,
I have 2 codes below which is almost the same but with difference answer.
Anyone can explain?
score = 1.8PHP Code:double score;
score = 9.00 / 5
vs
score =1PHP Code:double score;
score = 9 / 5
thanks,
Popskie
The difference lies in which division operator is called. In the first example the operator is /(double,int) which performs a floating-point division and returns a double, thus preserving the fraction. In the second example the operator is /(int,int) which performs an integer division thus discarding the fraction part. The result is then coerced to a double as per your variable type.
See also: C# Numeric Literals
Thanks penagate