Thema: Delphi Count digits after point

Einzelnen Beitrag anzeigen

swkevin08

Registriert seit: 21. Jul 2008
11 Beiträge
 
Delphi XE Professional
 
#11

AW: Count digits after point

  Alt 15. Feb 2014, 17:59
as the others have said, it has something to do with the approach.
but look at this. maybe it will help you!

ps: doenst work for all numbers! for example x,42300000000000000001

Edit: e was randomly generated

Code:
const
  e = 0.0000000001;

function CountDigitsAfterPoint(AValue: Extended): Byte;
var r: Extended;
begin
  Result := 0;
  r := Int(AValue);
  while ((Frac(AValue) <> 0) and ((AValue - r) > e)) do
  begin
    Inc(Result);
    AValue := AValue * 10;
    r := Int(AValue+e);
  end;
end;

Geändert von swkevin08 (15. Feb 2014 um 18:04 Uhr)
  Mit Zitat antworten Zitat