[Lazarus] formatfloat negative zero (-0)

Lukasz Sokol el.es.cr at gmail.com
Mon Jul 7 14:37:04 CEST 2014


On 07/07/14 13:13, Andrea Mauri wrote:
> Dear all,
> 
> using formatfloat function I got an unexpected behaviour.
> If I round negative numbers I can get as result of formatfloat = '-0'.
> I think it is a bug, since -0 has no meaning, zero is zero.
> How can I make a workaround?
> e.g.
> label1.Caption:= FormatFloat('0.###', strtofloat(edit1.Text));
> if in edit1.text I have -0.000001 I got -0 as result while I would like to get 0.
> 
> Is it a bug, what can I do?

Minus-zero is a recognized computational 'feature' of floats on computers, not a bug (AFAIK).

The float variable value of StrToFloat(edit1.text) is still -0.000001 though;
(try assigning it to a float type variable and watch it)

Does the same happen if you Round() it to integer? 
e.g.
label1.caption := Format('%d',[Round(strtofloat(edit1.text))]); 
(I know this isn't what you're after

> 
> Best regards,
> Andrea Mauri
> 
-L.






More information about the Lazarus mailing list