Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
double w;
w = 1280/170// = 7.0

Why not 7.5 ?
Posted

1 solution

Try it this way:

double w = 12780d / 170d;


When you do math with doubles, you have to use doubles in the expression.
 
Share this answer
 
Comments
Nish Nishant 25-Oct-10 20:07pm    
John, he's asking this from a Java perspective. Are you sure this works the same way in Java as in C#? (as in d being the suffix for double types)
Peter_in_2780 25-Oct-10 22:03pm    
You're right, Nish. Suffix 'd' doesn't work in Java. "123." is double, "123.f" is float.
[no name] 26-Oct-10 2:02am    
or:
double w = 10*1280 / 170;
w = w/10 // w = 7.5

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