|
-
March 7th, 2004, 09:53 PM
#4
Doing (double) 3/2 will not return the correct result, because Java will calculate the result as an integer division and round down to 1, then cast to a double giving 1.0.
Either specify one of two/three as a double or do the following:
result = 1.5 + (((double) three) / two)
Casting has low precedence in relation to arithmetic operations so it will cast the result if you don't use brackets rather than casting the number.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|