Page 1 of 1

Posted: Wed Oct 30, 2002 8:06 pm
by BackupUser
Restored from previous forum. Originally posted by TerryHough.

Could someone open my eyes. This doesn't seem to work as expected.

StringGadget(1, 20, 70,100,20,"") is used to enter a numeric amount with 2 decimal places. Eg. 100000.55

T$=GetGadgetText(1) ; get the string
Amount.f = ValF(T$) ; convert to a float value

Problem is that Amount always contains 100000.546875

Have I run up on a "flaw" or am I doing something wrong.

Thanks,
Terry

Posted: Wed Oct 30, 2002 9:09 pm
by BackupUser
Restored from previous forum. Originally posted by tinman.

Well, you can't store numbers like xxx.55 in a floating point number easily (or accurately with enough resolution).

Live with it, work with it as strings, or use longwords and parse it manually.


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.40)

Posted: Wed Oct 30, 2002 9:17 pm
by BackupUser
Restored from previous forum. Originally posted by Kale.

PB kindly provided me with this :)

Code: Select all

;convert a float to a string and round the float remainder to 'nPlaces' i.e. 103.879997 >> 103.88
Procedure.s floatToString(number.f, nPlaces.l)
    r=Pow(10,nPlaces)
    vf.f=number*r
    vs.s=Str(vf)
    rs.s=Left(vs,Len(vs)-nPlaces)+"."+Right(vs,nPlaces)
    ProcedureReturn rs
EndProcedure

Posted: Thu Oct 31, 2002 12:44 am
by BackupUser
Restored from previous forum. Originally posted by PB.

> PB kindly provided me with this [snip]

...which I originally got from Ron -- it wasn't all my work. :)


PB - Registered PureBasic Coder