on 8/30/01 6:12 AM, Francois Van Lerberghe at fvanlerberghe /AT/ freegates .DOT be wrote:
> I see some strange behavior with VFloat field : > > I store -18592.01 in it (with SetString or Value, no matter) > When I get the value, I see different values in the EditField with > GetString and Value : > > FloatField.GetString -> -18592 (same in VApp) > FloatField.Value -> -18592.0097656 > > With the value 12394.68, I get : > > FloatField.GetString -> 12394.7 (same in VApp) > FloatField.Value -> 12394.6796875 > > Using VDouble, I get the same value that I store.
Maybe in the examples you looked at; however, there will be others where this is not the case. > > 1/ Is there > - a mathematical issue > - a Valentina issue > - a RealBasic issue
Sort of all three. Basically the problem is representation of decimal numbers within the computer. Certain fractional forms are not precisely representable as a number.
> > 2/ Must I use VDouble field in order to retrieve safely the value I > stored ? > (I need 2 decimals precision because it's for storing money amount)
As noted above, using vDouble will not resolve your problem.
Store the money values as a string with two-decimals. Define a virtual method which converts that to a number; this can be used for sorting/find operations if needed. The string field can be brought into RB very easily and with no time penalty. Use the format function with a format specification "#.00" or "#,00" as needed.
Best regards, John Roberts
mailto:jarobe01@athena.louisville.edu ©2001 john roberts |