Normal Topic where is my cent? (Read 924 times)
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
where is my cent?
Mar 21st, 2012 at 11:23am
Print Post Print Post  
Hello!

I am using the following subroutine to calculate the sum, I can unfortunately do not understand why this sum is sometimes missing a cent !

For example:
Item1 Price:   36.87
item2 Price:   16.76
item3 Price:   23.46
item4 Price:   50.27
item5 Price:    5.60

Total        : 132.95 !


Here my Code:

Subroutine Calculate()
var vTotal as Double
vTotal = @SumListValues(@FormGetValues(sSub, "Betrag"))
Summe =vTotal
End Subroutine


thank you for the help.
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: where is my cent?
Reply #1 - Mar 21st, 2012 at 1:09pm
Print Post Print Post  
To avoid this type of issue, make sure that both your Betrag field and your vTotal variable are set to type Money.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: where is my cent?
Reply #2 - Mar 21st, 2012 at 1:45pm
Print Post Print Post  
Hello Erika!

Unfortunately this error is still not corrected!
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: where is my cent?
Reply #3 - Mar 21st, 2012 at 5:15pm
Print Post Print Post  
Hello Amor,

Run the following code instead. It will output the raw values from the subform, Copy and paste those values in to a reply so that I can see them. I am wondering if you are perhaps not dealing with the values you think you are and for example 36.87 is really 36.867

Code
Select All
Subroutine Calculate()
var vTotal as Double
Var vValues as String
vValues = @FormGetValues(sSub, "Betrag")
Writeln(vValues)
vTotal = @SumListValues(vValues)
Summe =vTotal
End Subroutine 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Rick_R
Full Member
***
Offline



Posts: 243
Joined: Jan 29th, 2010
Re: where is my cent?
Reply #4 - Mar 21st, 2012 at 11:37pm
Print Post Print Post  
Something that helps sometimes with this sort of problem is:

1) Multiply each value by 100 and put each result into an integer variable.
2) Add the variables into an integer variable.
(This can be done as a loop so you only need two variables.)
3) Divide the sum by 100 and put the result into a money or other two-decimal variable.

Of course, this assumes the values will never exceed the maximum value an integer variable can hold.
  
Back to top
 
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: where is my cent?
Reply #5 - Mar 22nd, 2012 at 10:38am
Print Post Print Post  
Hello Ray-

Here is the output:

36,8690;16,7555;23,4600;50,2780;5,6000
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: where is my cent?
Reply #6 - Mar 22nd, 2012 at 1:33pm
Print Post Print Post  
Amor wrote on Mar 22nd, 2012 at 10:38am:
36,8690 16,7555 50,2780


That's the problem right there. The money value stored in your subform has a digit in all 4 decimal places that a money value can store. Going forward I would change the programming that populates Betrag to use @Round() to round to 2 decimal places so that the value you are displaying is the whole value. I would also run a Mass Update on the sub-database of
Code
Select All
Betgag = @Round(Betrag, 2) 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: where is my cent?
Reply #7 - Mar 22nd, 2012 at 5:05pm
Print Post Print Post  
Ray-
thank you so much.
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged