I infow Member Licensed User Longtime User Aug 12, 2014 #1 Hi, I made a simple sum in a loop: Code: Copy Total = Total + biblio.IsNull(Cursor1.GetDouble("VALUE"),0) Log(Cursor1.GetDouble("ACERTO") & " " & TotalAcerto) Results: 0.0 0 194.45 194.45 -297.56 -103.11000000000001 103.11 -1.4210854715202004E-14 0.0 -1.4210854715202004E-14 After sum the negative -297.56 it gives a crazy number with lots of decimals. Help Please,
Hi, I made a simple sum in a loop: Code: Copy Total = Total + biblio.IsNull(Cursor1.GetDouble("VALUE"),0) Log(Cursor1.GetDouble("ACERTO") & " " & TotalAcerto) Results: 0.0 0 194.45 194.45 -297.56 -103.11000000000001 103.11 -1.4210854715202004E-14 0.0 -1.4210854715202004E-14 After sum the negative -297.56 it gives a crazy number with lots of decimals. Help Please,
I infow Member Licensed User Longtime User Aug 12, 2014 #2 Just for note I removed the IsNull function, but the problem remains.
klaus Expert Licensed User Longtime User Aug 12, 2014 #3 To display numbers you should use NumberFormat or NumberFormat2. Not all decimal number can be represented exactly in binary format, that's why you get -103.11000000000001.
To display numbers you should use NumberFormat or NumberFormat2. Not all decimal number can be represented exactly in binary format, that's why you get -103.11000000000001.
I infow Member Licensed User Longtime User Aug 12, 2014 #4 The sum of 194.45+(-297.56), its not supposed generate .11000000000001 but only .11 Really strange behavior. I will try round it up. Last edited: Aug 12, 2014
The sum of 194.45+(-297.56), its not supposed generate .11000000000001 but only .11 Really strange behavior. I will try round it up.
I infow Member Licensed User Longtime User Aug 12, 2014 #5 By the way, thanks for the prompt response!
I infow Member Licensed User Longtime User Aug 12, 2014 #6 The main problem its that we have to convert to string to again convert to double every sum, its that correct?
The main problem its that we have to convert to string to again convert to double every sum, its that correct?
K keirS Well-Known Member Licensed User Longtime User Aug 12, 2014 #8 infow said: The sum of 194.45+(-297.56), its not supposed generate .11000000000001 but only .11 Really strange behavior. I will try round it up. Click to expand... Using AGrahams BigNumbers library will solve your issues as you can set the precision for the numbers. It's a must if you are performing calculations involving currency (money) or anything which requires precision. Code: Copy Dim bg1 As BigDecimal Dim bg2 As BigDecimal bg1.Initialize("1.40") bg2.Initialize("165") bg2.Multiply(bg1) Log(bg2.ToString) Log(1.40 * 165) The example gives the result of 231.00 for the BigDecimal calculation and 230.99999999999997 for 1.40 * 165. By the way this isn't a bug it's how IEEE floating point arithmetic works. Last edited: Aug 12, 2014
infow said: The sum of 194.45+(-297.56), its not supposed generate .11000000000001 but only .11 Really strange behavior. I will try round it up. Click to expand... Using AGrahams BigNumbers library will solve your issues as you can set the precision for the numbers. It's a must if you are performing calculations involving currency (money) or anything which requires precision. Code: Copy Dim bg1 As BigDecimal Dim bg2 As BigDecimal bg1.Initialize("1.40") bg2.Initialize("165") bg2.Multiply(bg1) Log(bg2.ToString) Log(1.40 * 165) The example gives the result of 231.00 for the BigDecimal calculation and 230.99999999999997 for 1.40 * 165. By the way this isn't a bug it's how IEEE floating point arithmetic works.