Re: Stange problem with sprintf or trace display

new topic     » goto parent     » topic index » view thread      » older message » newer message
AJ_Oxley said...

Thanks Matt,
The problem is that I am trying to save the data as characters, so will need to use value() and sprintf() quite a bit when fetching / displaying / accepting input.
In essence you are suggesting that a user may not enter numeric data as chars that contain a period, because of the rounding errors?
Possible bypass is to have seperate list controls designated for dollars and cents; the user would have to tab accross to the cents.
That won't make me popular!

Just split the number on the decimal and combine the two values:

-- this is straight out of my head, 
-- it may not work if actually run 
function decimal_from_string( sequence str ) 
 
    if find( '.', str ) then 
 
        sequence parts = split( str, '.' ) 
        sequence val1 = value( str[1] ) 
        sequence val2 = value( str[2] ) 
 
        return val1[2] + (val2[2] / 100) 
 
    else 
 
        -- no decimal here 
        sequence val = value( str ) 
 
        return val[2] 
 
    end if 
 
end function 

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu