<div dir="ltr"><div>Will straight forward solution work?</div>how about this:<div><br></div><div>unit MySysUtils;<br></div><div><br></div><div>interface</div><div><br></div><div>uss SysUtils;</div><div><div><br></div><div>
// the function will cut heading "-" if all digits in the number are zeros. </div><div>// it will leave the result unchanged otherwise.</div><div><br></div><div>function FormatFloat(const fmt: string; num: double): string;</div>
</div><div>var </div><div> i : integer;</div><div>begin</div><div> Result:= SysUtils.FormatFloat(fmt, num);</div><div> if (Result<>'') and (Result[1]='-1') then begin</div><div> for i:=2 to length(Result) do</div>
<div> if Result[i] in ['1'..'9'] then Exit;</div><div> Result:=Copy(Result, 2, length(Result)-1);</div><div> end;</div><div> </div><div>end;</div><div>....</div><div>in your program. Put "MySysUtils" as the last unit in the uses section (so your working unit would use MySysUtils FormatFloat, instead of the implementation at SysUtils)</div>
<div><br></div><div>thanks,</div><div>Dmitry</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 7, 2014 at 5:00 PM, Andrea Mauri <span dir="ltr"><<a href="mailto:andrea.mauri.75@gmail.com" target="_blank">andrea.mauri.75@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
using formatfloat function I got an unexpected behaviour.<br>
If I round negative numbers I can get as result of formatfloat = '-0'.<br>
I think it is a bug, since -0 has no meaning, zero is zero.<br>
How can I make a workaround?<br>
e.g.<br>
label1.Caption:= FormatFloat('0.###', strtofloat(edit1.Text));<br>
if in edit1.text I have -0.000001 I got -0 as result while I would like to get 0.<br>
<br>
Is it a bug, what can I do?<br>
</blockquote>
<br>
Minus-zero is a recognized computational 'feature' of floats on computers, not a bug (AFAIK).<br>
<br>
The float variable value of StrToFloat(edit1.text) is still -0.000001 though;<br>
(try assigning it to a float type variable and watch it)<br>
</blockquote>
<br></div>
OK, I understand that computationally -0 has meaning (since as you said the float variable value of StrToFloat(edit1.text) is still -0.000001).<br>
Anyway It has no meaning for the final user of the application (at least for any standard user of an application).<br>
The final user does not care that -0 has meaning for the computer.<br>
e.g. I would like to represent a float value with 3 decimal digits. I don't care of the remaining digits, -0.000 has no meaning, it just means that there are some digits (somewhere after the third decimal digits) that are not equal to zero and that if they are considered the value is negative (but I don't want to consider any digit after the third decimal one!).<br>
Try to do it in excel or libreoffice:<br>
- write in a cell -0.00001 and set to 3 the decimal digits, you got -0.000 or 0.000?<br>
And you got the same results using any software that deals with numbers..<div class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Does the same happen if you Round() it to integer?<br>
e.g.<br>
label1.caption := Format('%d',[Round(strtofloat(<u></u>edit1.text))]);<br>
(I know this isn't what you're after<br>
</blockquote>
<br></div>
In this way I got 0.<br>
Anyway I used as example formatfloat since it has the same behaviour of TFloatField.DisplayFormat, additionally DisplayFormat is a property that is used to represent a formatted value to the final user (a human being not a pc) for whom -0 has no meaning.<span class="HOEnZb"><font color="#888888"><br>
<br>
A.</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Best regards,<br>
Andrea Mauri<br>
<br>
</blockquote>
-L.<br>
<br>
<br>
<br>
--<br>
______________________________<u></u>_________________<br>
Lazarus mailing list<br>
<a href="mailto:Lazarus@lists.lazarus.freepascal.org" target="_blank">Lazarus@lists.lazarus.<u></u>freepascal.org</a><br>
<a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus" target="_blank">http://lists.lazarus.<u></u>freepascal.org/mailman/<u></u>listinfo/lazarus</a><br>
<br>
</blockquote>
<br>
--<br>
______________________________<u></u>_________________<br>
Lazarus mailing list<br>
<a href="mailto:Lazarus@lists.lazarus.freepascal.org" target="_blank">Lazarus@lists.lazarus.<u></u>freepascal.org</a><br>
<a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus" target="_blank">http://lists.lazarus.<u></u>freepascal.org/mailman/<u></u>listinfo/lazarus</a><br>
</div></div></blockquote></div><br></div>