Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternatives to Str or FloatToStr? 1

Status
Not open for further replies.

Glenn9999

Programmer
Jun 19, 2004
2,311
US
When I profile a program I have here, I notice one spot takes up about 38% of my total processing time.

That spot happens to be "Str" or "FloatToStr". Does anyone know a good alternative to that?

Thanks.
 
Not sure. FloatToStr calls FloatToText and FloatToText is written in assembler.

If you are not fomatting (ie: marking millions and thousands "1:123,123.12") but only converting you can try something like:

Code:
// Decs: decimal places
QuickRealToStr(x : real; Decs : integer) : AnsiString;
var
  IntPart : integer;
  FracPart: integer;
begin
  // Convert the real (float) to two integers.
  IntPart := Round(Int(x));
  FracPart := Round(Frac(x)));
  // Take the desired decimal digits
  Result := IntToStr(FracPart);
  Result := Copy(Result, 1, Decs);
  // Create the output string
  Result := IntToStr(Int) + '.' + Result;
end;

// NOTE: Code written on the fly, may have errors.

Frac, Int and Round are all little functions written in assembler and using the copro. IntToStr is written in PASCAL, we are betting it being more efficient than FloatToTex. Not sure about the outcome.

Let me know the results you get, please.

buho (A).


 
Copro = FPU.

Sorry, I was born in the jurassic.

buho (A).
 
This wasn't exactly what I needed, but I tried something similar and ended up running 0.6 secs slower.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top