Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 6 Jahren, 9 Monaten
Letzter Beitrag:
vor 6 Jahren, 9 Monaten
Beteiligte Autoren:
Milton, Jimbo, Stefan Bentvelsen, Maja.pcs.crosspost

Calculation problem

Startbeitrag von Maja.pcs.crosspost am 13.05.2011 14:38

Hi to all :)

I am having a calculation problem in my sample project and i am hoping someone will help me.

I have two edit boxes first one is PriceWithoutVat 2,21 and second one is Vat 0,22

When i try to sum those two and show the result in third one called PriceWithVat result is 2,44 ??????????

How come? 2,21+0,22 is 2,43, can you tell me what i am doing wrong?
In analysis those fields are marked as currency. I tried numeric, decimal and result is the same.

How can i sum items and be sure that the result will be precise, not one cent higher or lower? Some exaple code would be much appriciated.

Message forwarded from pcsoft.us.windev


Hi Maja,

I think, in your file there will be more decimals then 2, i.e. 2.214 en .223. The sum is then 2.437, which becomes 2.44 in your control ?

von Stefan Bentvelsen - am 13.05.2011 15:06

Hi, remember: in fact you don't sum up the two edit boxes - you are calculating the sum of the two related variables. 4-byte reals are not precise enough - use currency type instead or a proper rounding algorithm on 8-byte reals. Do not use Round(..). Regards, Guenter

von Jimbo - am 13.05.2011 16:00
Hi Maja,

One simple way of doing this is to multiply your original figure without VAT by 1.11 which will then give you the figure with VAT. This avoids adding rounding errors.

So, 2.21 x 1.11 = 2.431 which rounds to 2.43.

I knew learning decimals at school would one day come in handy.


von Milton - am 13.05.2011 21:45
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.