division operation

Bonowox

New member
Local time
Today, 20:35
Joined
Jun 13, 2018
Messages
10
Hello everyone!
Why is my query not showing the correct result when dividing two numbers?
For example:
if I divide -24.40 by 24.40 I get the result -0.983870967741935
or if I divide -24.80 by -24.80 I get the result -0.873239436619718
But it's not like that every time. In the query table, I have several divisions with these numbers, and sometimes it shows me the correct result, sometimes not
 
You have defined the datatype for your field as Double or Single floating point.

These datatypes will have rounding errors.

Use Decimal datatype instead or, even better, Currency if you are not interested in more than 4 decimal places
 
You have defined the datatype for your field as Double or Single floating point.

These datatypes will have rounding errors.

Use Decimal datatype instead or, even better, Currency if you are not interested in more than 4 decimal places
Yes, but regardless of defining the field -24.40/24.40=-1
Why does it give me an error in the calculation and is it possible to fix it?
 
Where are your numbers coming from?
Are you sure you have the full values in mind? Or are parts of the numbers hidden by formatting?

A deviation of about 1.6 percent is not solely due to the flow number problem.
 
Dug_najamnina_yes Dug_najamnina_yes
This is what the query table looks like
Where: Expr1: [Uplatio]-[Zaduzen]
and Expr2: ([Expr1]/[Iznos])
KorisnikIDZaduzenUplatioExpr1Izraz1Expr2
Aziri (Tefik) Zaim
6.265,10 KM​
6.212,10 KM​
-53,00 KM​
53,00 KM​
-1​
Bajrami (Sejdija) Almir
6.818,70 KM​
6.487,50 KM​
-331,20 KM​
55,20 KM​
-6​
Baraković (Duran) Muškija
24,40 KM
0,00 KM
-24,40 KM
24,40 KM
-1
Batlak (Adem) Samira
24,40 KM
0,00 KM
-24,40 KM
24,40 KM
-1
Behram (Islam) Jusuf
24,40 KM
0,00 KM
-24,40 KM
24,80 KM
-0,983870967741935
Berhamović (Husein) Jasmina
24,40 KM​
0,00 KM​
-24,40 KM​
24,40 KM​
-1​
Božović (Branko) Žarko
24,80 KM
0,00 KM
-24,80 KM
28,40 KM
-0,873239436619718
Čelebić(Senad) Sanela
2.600,00 KM​
2.574,00 KM​
-26,00 KM​
26,00 KM​
-1​
Čevriz (Radoslav) Vasilija
3.828,90 KM​
3.797,90 KM​
-31,00 KM​
31,00 KM​
-1​
Ćatić (Meho) Alija
396,00 KM​
352,00 KM​
-44,00 KM​
44,00 KM​
-1​
Ćatović (Murat) Ismet
208,00 KM​
156,00 KM​
-52,00 KM​
26,00 KM​
-2​
Ćenan (Meho) Ramiza
24,40 KM​
0,00 KM​
-24,40 KM​
24,40 KM​
-1​
Ćenan (Mirzo) Erna
24,40 KM​
0,00 KM​
-24,40 KM​
24,40 KM​
-1​
Ćimić (Omer) Emir
3.024,00 KM​
3.052,00 KM​
28,00 KM​
28,00 KM​
1​
Ćupina (Murat) Šefika
24,80 KM​
0,00 KM​
-24,80 KM​
24,80 KM​
-1​
Ćurčin (Esad) Hafiza
275,20 KM​
206,40 KM​
-68,80 KM​
34,40 KM​
-2​
This is what the query table looks like
Where: Expr1: [Uplatio]-[Zaduzen]
and Expr2: ([Expr1]/[Iznos])
I have marked the correct calculation fields in green, and the incorrect ones in red
Thanks!
 
This is what the query table looks like
My hint was about how the values are defined, not what they look like.

If you pour vinegar out of a champagne bottle, it's still vinegar. It won't be champagne. You see it, you taste it. But you have to turn on your senses.
 
My hint was about how the values are defined, not what they look like.

If you pour vinegar out of a champagne bottle, it's still vinegar. It won't be champagne. You see it, you taste it. But you have to turn on your senses.
Ok, but I'm curious why it shows a different result in these two cases, and the whole query is defined the same. Maybe I'm a bit boring but ....sorry I'm not clear
24,40 KM0,00 KM-24,40 KM24,40 KM-1
24,40 KM0,00 KM-24,40 KM24,80 KM-0,983870967741935
 
First, your query info as shown in post #8 uses a different name than the column labels... Iznos vs. Izraz1 - so I can't tell if that should be the same or not. But assuming it is, you have that "Behram (Islam) Jusuf" row that you are complaining about, where you divide -24.40 / 24.80 - which according to my PC's calculator app is -0.9838709655419355, and I therefore don't see your problem. Then, from post 8 again, the line for "Božović (Branko) Žarko" shows -24.80 / 28.40 - which my PC calculator says is -0.8732394366197183

I would do some data checking.
 
First, your query info as shown in post #8 uses a different name than the column labels... Iznos vs. Izraz1 - so I can't tell if that should be the same or not. But assuming it is, you have that "Behram (Islam) Jusuf" row that you are complaining about, where you divide -24.40 / 24.80 - which according to my PC's calculator app is -0.9838709655419355, and I therefore don't see your problem. Then, from post 8 again, the line for "Božović (Branko) Žarko" shows -24.80 / 28.40 - which my PC calculator says is -0.8732394366197183

I would do some data checking.
Thank you very much my friend
 
Please check and let us know the datatypes of fields Uplatio, Zaduzen and Iznos in design view of your table.

Make sure you check the 'Field Size' property in the 'General' tab for each field.
 
The calculations in red look correct too:
Code:
-24,40 KM / 24,80 KM = -0,983870967741935
-24,80 KM / 28,40 KM = -0,873239436619718
 
As @cheekybuddha informed you back in post #2, Double and Single are prone to floating point errors because binary (how the data is stored in single/double) cannot always be converted cleanly to decimal (how the data is displayed). Unless you actually need all those decimal places, convert the data type to Currency or Decimal.

Here's an article that sheds some light on the issue.
 

Users who are viewing this thread

Back
Top Bottom