[Gambas-user] ODBC and NUMERIC problem

Daniel Campos dcamposf at ...626...
Wed Dec 5 21:12:42 CET 2007


Yes nando, you're quite right, it is quite dangerous to use float
values for currency, just adding a decimmal coma for the human final
interface is quite better

2007/12/5, nando <nando_f at ...951...>:
> I'd like to give my personal opinion here.
> When using writing code dealing with money and
> the variable used in Gambas is FLOAT, you will
> have problem with pennies.  FLOAT does not
> represent money properly.
>
> For example $ 2.33 is not 2.33 when saved as a float
> because floating point binary cannot represent many
> fractional values exactly.
>
> I always use INTEGER and store money as cents, not dollars and cents.
> I know many that are doing this the same way.
>
> For money, the precision and exactness is non better.
>
> So then,
>
> DIM i AS INTEGER
> i = 233  'this is 233 cents
>
> You will never have problems in code.
>
> In MySQL, use INT, not Numeric, not anything else.
>
> When you have to display values, use FORMAT with i/100. to make it a float
> for visual representation.
>
> Start now, and you will never have problems.
> You will always know your data within the program is exact
> and the match will be exactly correct.
>
> -Fernando
>
>
> ---------- Original Message -----------
> From: Andrea Bortolan <andrea_bortolan at ...325...>
> To: mailing list for gambas users <gambas-user at lists.sourceforge.net>
> Sent: Wed, 5 Dec 2007 09:23:36 +0000 (GMT)
> Subject: Re: [Gambas-user] ODBC and NUMERIC problem
>
> > Hi,
> > can you please provide me also the SQL trace taken running the query in isql and
> >  a second trace running the same query from the  Gambas  program? You can enable
> > it using the ODBCConfig tool, in the Advance tab flag the trace. What DB are you
> > connecting to  ?
> >
> > Thanks, Andrea.
> >
> > ----- Messaggio originale -----
> > Da: esucno esucno <esucno at ...626...>
> > A: gambas-user at lists.sourceforge.net
> > Inviato: Mercoledì 5 dicembre 2007, 0:29:24
> > Oggetto: [Gambas-user] ODBC and NUMERIC problem
> >
> > Hi everybody,
> >
> > i have a problem with gambas2 and odbc:
> >
> > when a use isql (from unixodbc), I get this result:
> >
> > *select  product, price from products
> > - banana ~ 5.00
> > - orange ~ 7.00
> > - apple ~ 5.00
> >
> > but, when a use gambas (from the example), I get this result:
> >
> > *select  product, price from products
> > - banana ~ 234235
> > - orange ~ 234238
> > - apple ~ 234241
> >
> > i'm doing something wrong or its a bug?
> >
> > ___________
> > Gambas 1.9.91
> > os: Opensuse 10.3
> > odbc: unixODBC 2.2.12
> > driver odbc: libOdbcFb32.so V2.0 (Beta 02.00.00.0144)
> > format of "PRICE": NUMERIC(8,2)
> > *
> > *
> > Thanks in advance
> >
> > --
> > Edward Sucno Quiroz
> > -------------------------------------------------------------------------
> > SF.Net email is sponsored by: The Future of Linux Business White Paper
> > from Novell.  From the desktop to the data center, Linux is going
> > mainstream.  Let it simplify your IT future.
> > http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> >       ___________________________________
> > L'email della prossima generazione? Puoi averla con la nuova Yahoo! Mail:
> http://it.docs.yahoo.com/nowyoucan.html
> > -------------------------------------------------------------------------
> > SF.Net email is sponsored by: The Future of Linux Business White Paper
> > from Novell.  From the desktop to the data center, Linux is going
> > mainstream.  Let it simplify your IT future.
> > http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> ------- End of Original Message -------
>
> -------------------------------------------------------------------------
> SF.Net email is sponsored by: The Future of Linux Business White Paper
> from Novell.  From the desktop to the data center, Linux is going
> mainstream.  Let it simplify your IT future.
> http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>




More information about the User mailing list