0

double x = 5/2; vs double y =5.0/2.0; in C#

Hey I noticed this "problem" during making solution for Helloween Candy and i dont understand why even if i declare type double i got rounded result when x = 2 not correct 2.5 Do i use wrong type?

15th Jul 2020, 10:51 PM
Mr Wolfy
Mr Wolfy - avatar
2 Respuestas
+ 5
From what I know : - first case : 5 and 2 are integer and are interpreted as integer. Their division produces an integer. So 5 / 2 is 2. - second case : 5 and 2 are floats. Their division produces a float. So 5.0 / 2.0 is 2.5.
15th Jul 2020, 11:01 PM
Théophile
Théophile - avatar
0
Okey i understand, hmm but can i somehow set which side integer operation is round? I found methods only for round double
17th Jul 2020, 7:38 PM
Mr Wolfy
Mr Wolfy - avatar