The problem with FloatToStrF is, the digit parameter limit the output of resulted string, e.g: FloatToStrF(1/1000,10,10) will result 0.001000000. That's why I made the function FloatToStrNP which will convert the floating-point into string using FloatToStrF and then remove all trailing zeros (1/1000 = 0.001). This function of mine works just fine, but I wonder if there are much more efficient way to convert float to string without scientific notation and no trailing zeros, because my function involves many (yes, I consider it many...) operations which can affect the performance of the rapid calculation I'm going to perform with it.
--------------------- CoolKid K-Qha http://kha.web.id --------------------- --- On Sun, 8/10/08, Sean Roberts <[EMAIL PROTECTED]> wrote: From: Sean Roberts <[EMAIL PROTECTED]> Subject: RE: [advanced_delphi] FloatToStrF without zero padding To: advanced_delphi@yahoogroups.com Date: Sunday, August 10, 2008, 9:37 PM Please provide a sample number (val) that gets the padding you don't want. I would like to use this number to see if I can get the function work the way you want it to. XFX nForce 680i LT SLI Socket 775 | Intel Core 2 Duo E6750 OC:1600 FSB @ 3.2 MHz | 2 x OCZ SLI 1024MB PC6400 DDR2 800MHz| XION 600w PSU | CM Stacker 200 ATX/BTX Case | EVGA GeForce 8800 GTS 512 | WD SATA 74 GB Raptor (boot/system) , WD SATA 500 GB (storage) | Windows XP Pro, SP3 | Patient and supportive significant other To: advanced_delphi@ yahoogroups. com From: [EMAIL PROTECTED] com Date: Sun, 10 Aug 2008 00:05:27 -0700 Subject: [advanced_delphi] FloatToStrF without zero padding Greeting, Did anyone know how to use FloatToStrF without zero padding? I need it because my code must avoid the usage of scientific notation, thus I used FloatToStrF with ffFixed format. But later I found out that the output of resulted string was padded with zeros. For temporarily, I use these code to remove all zero padding but still there must be some way which is more efficient... ---code begin--- function TDMod.FloatToStrNP( val : extended) : string ; var a : integer ; txt,retval : string ; begin txt := FloatToStrF( val,ffFixed, 18,18) ; retval := '' ; for a:=Length(txt) downto 1 do begin if (txt[a]='0') and (retval <> '') then retval := txt[a]+retval else if txt[a]<>'0' then retval := txt[a]+retval ; end ; Result := retval ; end; ---code end--- ------------ --------- CoolKid K-Qha http://kha.web. id ------------ ---------