AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Count digits after point

Ein Thema von WojTec · begonnen am 15. Feb 2014 · letzter Beitrag vom 15. Feb 2014
Antwort Antwort
Benutzerbild von Aphton
Aphton

Registriert seit: 31. Mai 2009
1.198 Beiträge
 
Turbo Delphi für Win32
 
#1

AW: Count digits after point

  Alt 15. Feb 2014, 15:41
@DelphiProgrammer:
Nope!

Delphi-Quellcode:
var
  x: Single;

begin
  x := 2.048;
  writeln(x);
  writeln((length(floattostr(x)) - pos('.',floattostr(x))-1));
  readln;
end.
Output
Code:
 2.04800009727478E+0000
15
das Erkennen beginnt, wenn der Erkennende vom zu Erkennenden Abstand nimmt
MfG
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#2

Re: Count digits after point

  Alt 15. Feb 2014, 15:51
I thought about strings too, but (1) it's lame and (2) see @Aphton's post.

There is no math solution?
  Mit Zitat antworten Zitat
Benutzerbild von Aphton
Aphton

Registriert seit: 31. Mai 2009
1.198 Beiträge
 
Turbo Delphi für Win32
 
#3

AW: Count digits after point

  Alt 15. Feb 2014, 16:07
This might be a problem that can be solved in another way.
You want to find out the number of fraction-digits.
Why?
Maybe the root problem you are trying to solve can be solved in another way! Maybe you dont even need to find out the digitcount!
das Erkennen beginnt, wenn der Erkennende vom zu Erkennenden Abstand nimmt
MfG
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.875 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: Count digits after point

  Alt 15. Feb 2014, 16:09
Why you need the number of digits? perhaps there is a better way to achieve your aim.
Markus Kinzler
  Mit Zitat antworten Zitat
Benutzerbild von Aphton
Aphton

Registriert seit: 31. Mai 2009
1.198 Beiträge
 
Turbo Delphi für Win32
 
#5

AW: Count digits after point

  Alt 15. Feb 2014, 16:10
@mkinzler: xDD
das Erkennen beginnt, wenn der Erkennende vom zu Erkennenden Abstand nimmt
MfG
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#6

Re: Count digits after point

  Alt 15. Feb 2014, 16:50
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.
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.875 Beiträge
 
Delphi 11 Alexandria
 
#7

AW: Count digits after point

  Alt 15. Feb 2014, 16:56
For (1) because the system iminent computation error the consumption more digits are better doesn't seem right to me.
For (2) I'd prefer to restrict the digits to dispay to a fixed count
Markus Kinzler
  Mit Zitat antworten Zitat
swkevin08

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

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
Furtbichler
(Gast)

n/a Beiträge
 
#9

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
Antwort Antwort


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 14:30 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz