subtraction « double « Java Data Type Q&A





1. Subtraction of numbers double and long    stackoverflow.com

In my JAVA program there is code like this:

int f_part = (int) ((f_num - num) * 100);
f_num is double and num is long. I just want to take the fractional part ...

2. Double subtraction error    coderanch.com

The users where I work found an interesting problem that I've been trying to figure-out. I've got a workaround coded and out to them but I'm still confused about how in the world there was a problem in the first place. The code below illustrates the problem. I start with variable dCheckAmt with a dollar amount of 7.79. It goes through ...

3. addition and subtraction in double    coderanch.com

no. Floating point arithmetic is limited by the precision of your hardware and cannot be guaranteed to have no difference in far decimal places. You can of course use Math.round() to turn the result into a long if you so wish but that won't help you in realistic cases where the result is a floating point number of its own. Another ...

4. double subtraction    coderanch.com

5. Subtraction of double values    coderanch.com

I am doing the following subtraction using 2 double values class temp { public static void main(String[] args) { double d = 200.123; double f = 100.123; double t = d - f; System.out.println("t " + t); } } Ans: t 99.99999999999999 I get the result as above instead of 100. Can anyone tell me why this is happening? Also, similar ...

6. Double subtraction    java-forums.org

In subtracting one double from another, namely 45.32 - 45.31, I get a result of 0.00999999999999801. According to all the math I've ever learned, the answer should be .01. I asked my professor about this, and his response was that "45.31 may be a repeating decimal." To which I responded, "I have no idea what that means." Help please!

7. Subtraction with Doubles    forums.oracle.com

Thanks for all your help, I understand whats happening a bit now, not fully though (e.g. why a - can reproduce this effect and the + doesn't). I found this effect very strange as I've never heard of it before. I'll try to implement a suitable work around now as the input data into my program will be decimals ranging from ...