[Gambas-user] About financial program in Gambas

nando nando_f at ...951...
Wed Dec 16 22:13:51 CET 2009


For your info only...
I always use INT or LONG for accounting and money.
So, (here in Canada), $42.87 is 4287
I keep the tax (8%) as a float, therefore 8.25% is 8.25
This is ok for tax because rounding is needed.
For example:

4287 * 8.25 = 35367.75 / 100 = 353.6775
add .5 for 5/4 round up down
= 354.1775
Plase result into INT var which becomes 354

4287 + 354 = 4641

Using Float for taxes allows for many decimal places.
Using 100 for /100 process allows for any currencies where 
you want more than 2 decimal places.

For correct printing without rounding errors, do not do 4287/100.
but rather take the STR$(4287),
then split the right two off, and place a decimal in that place.
Perfect math and exact calculations every single time!!!

-Fernando


---------- Original Message -----------
From: Ricardo Díaz Martín <oceanosoftlapalma at ...626...>
To: mailing list for gambas users <gambas-user at lists.sourceforge.net>
Sent: Wed, 16 Dec 2009 10:46:40 +0000
Subject: Re: [Gambas-user] About financial program in Gambas

> Jean,
> 
> You can use numbers of decimal as you want. I you want 4 you only need to
> divide by 1000. The only you need to decide on before insert data. If you
> need to add more decimals in future you only have to modify a parameter in
> your app from 2 to 4 (functions that show from database/write to database
> currency values must read this values before show/write info) and update
> your database multiplying cur fields by 100 (to add two digit more of
> precision)
> 
> You never need truncate any value if you always use this especial currency
> type. For example if you set decimals to 4, number 19.99657 is no possible.
> 
> If you need to get selling prices using four decimal coefficient, define
> coefficient as a currency type and set your app to use 4 decimal for all
> "currency" values
> 
> I hope this helps you
> 
> 2009/12/16 Jean-Yves F. Barbier <12ukwn at ...626...>
> 
> > Ricardo Díaz Martín a écrit :
> > > Hi to all,
> > >
> > > I'm use gambas to write ERP applications. At the first, I got the same
> > > problem but I decided to use long integer to save currency values. First
> > > rigth two digits are always showed to users as decimal values.
> > >
> > > I'm rewrited all my apps from windows to gambas and they are working now
> > > with no problems in customers servers.
> > >
> > > I allways use a function to show values in controls in app's forms that
> > > convert database fields values showed in textboxes whose name started int
> > > dbcur (p.e. dbcurVAT) to value div 100 and works with no problems. I use
> > > allways the same function to write forms data to database and make the
> > > reverse proccess.
> >
> > Hooo, thanks for the ad.
> >
> > > Its simple and works
> >
> > Sounds exactly like the commercial about women thin down cream we've
> > got on tv for months (it works!) (sorry, I couldn't resist:)
> >
> > So you're truncating everything to 2 decimals, but as I said VAT (and as
> > a matter of fact almost all french taxes) is *legally* up to 4 decimals;
> > actually only 2 of them are used, but nothing's saying that tomorrow
> > is won't be 3 or 4 really used (especially on those times where our
> > gov morons (pleonasm) are desesperatly looking for money.)
> >
> > BTW, how do you truncate 19.99657? Down to 19.99 or up to 20.00?
[WINDOWS-1252?]> > In my family's company a cent error is worth €100,000 fine...
> >
> > Other PB: most of results could be predictable (as of Nb of decimals),
> > but some can't (ie: 92.95x1.196=111.1682 OR 145x1.196=173.42),
> > maths says decimals should be dN1+dN2=5 but in these cases we only have
> > 4 and 2 because of non-significant right zeroes, so you can't obviously
> > truncate by adding the comma counting 5 from the right.
> > One of the most used manner to get a selling price is to use a coefficient
> > which has many decimals (usually a real), how do you determine where to
> > put the comma in the resultant number??
> >
> > I see the possibilities, but AFAIK this is a full processor to write
> > based on a complex numbers model, not to mention error possibilities
> > have a tremendous cataclysmic potential in a matter where tax
> > administration will be more than happy to chop your head and piss
> > on your brain (yeah, they're like that here: when they come it is
> > not to search, it is to find; no matter if has real justification or not.)
> >
> > But may be I'm totally mistaking: I always have had PBs with simple
> > things.
> >
> > JY
> > --
> > God is real, unless declared integer.
> >
> >
> > ------------------------------------------------------------------------------
> > This SF.Net email is sponsored by the Verizon Developer Community
> > Take advantage of Verizon's best-in-class app development support
> > A streamlined, 14 day to market process makes app distribution fast and
> > easy
> > Join now and get one step closer to millions of Verizon customers
> > http://p.sf.net/sfu/verizon-dev2dev
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> ------------------------------------------------------------------------------
> This SF.Net email is sponsored by the Verizon Developer Community
> Take advantage of Verizon's best-in-class app development support
> A streamlined, 14 day to market process makes app distribution fast and easy
> Join now and get one step closer to millions of Verizon customers
> http://p.sf.net/sfu/verizon-dev2dev 
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------




More information about the User mailing list