main logo
Subject: Re: [V4RB] VFloat - strange behavior
Author: Charles Yeomans
Posted: 2001/08/30 10:13:09
 
View Entire Thread
New Search


On Thursday, August 30, 2001, at 07:30 AM, john roberts wrote:

> on 8/30/01 6:12 AM, Francois Van Lerberghe at fvanlerberghe /at/ freegates .DO.T 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.
>

I think it's best to store money values as a double, passing an integer
value. In V4RB, I'm writing a billing application and I use Money and
Currency objects (the latter being overkill, for now) and work with
those. There is a nice discussion in "Analysis Patterns" by Martin
Fowler on the utility of using such objects for various quantities and
measurements.

Charles Yeomans
 
©2001 Charles Yeomans
<-- Prior Message New Search Next Message -->