Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
double x = 74/120;

Expected: 0.6166666... But the result is 0. Why ?
Posted
Comments
Thomas ktg 2-Jan-14 6:41am    
Show some code you have written for this.

74 and 120 are integers so the division will return an integer and then convert it to double.
Try 74.0 / 120.0
 
Share this answer
 
You can also use cast like this,
C#
double number3 = (double)number1/(double)number2;


For more information refer here,
http://www.dotnetperls.com/divide[^]
 
Share this answer
 
v2
cast the integers to double ..you will get the expected result
 
Share this answer
 
try this..

C#
double x = (double)74 / (double)120;
 
Share this answer
 
try this
C#
double x = 74d/120d;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900