AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Count digits after point

Ein Thema von WojTec · begonnen am 15. Feb 2014 · letzter Beitrag vom 15. Feb 2014
Antwort Antwort
Seite 2 von 2     12
swkevin08

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

AW: Count digits after point

  Alt 15. Feb 2014, 16: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 17:04 Uhr)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#12

Re: Count digits after point

  Alt 15. Feb 2014, 17:49
Thanks, for all values I used early, is working correctly.
BTW: why e has that value, can have other values?
  Mit Zitat antworten Zitat
swkevin08

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

AW: Count digits after point

  Alt 15. Feb 2014, 18:32
e is just a small number close to zero. it doesn't matter if there's one zero more or one less.
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#14

AW: Re: Count digits after point

  Alt 15. Feb 2014, 20:53
Thanks, for all values I used early, is working correctly.
BTW: why e has that value, can have other values?
Have a look at the documentation Delphi-Referenz durchsuchenSystem.Math.SameValue and Delphi-Referenz durchsuchenSystem.Math.CompareValue and read what is the meaning of Epsilon.

Another helpful article is http://en.wikipedia.org/wiki/Machine_epsilon
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)

Geändert von Sir Rufo (15. Feb 2014 um 20:56 Uhr)
  Mit Zitat antworten Zitat
Furtbichler
(Gast)

n/a Beiträge
 
#15

AW: Re: Count digits after point

  Alt 15. Feb 2014, 21:07
So, reason is not important. Important is problem.
But if you want to know: (1) result is required for further computation purposes and (2) for formating.
The reason is always important, especially when people don't seem to exactly know what they are talking about.

Showing the number of decimals is definitely not something to please the eye. It is showing the accuracy of your value, so a value of, say, 100 (metres) measured up to a mm is correctly shown as "100,000 m" whereas the same value with an accuracy of 1m is shown as "100m".
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:36 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz