DGL
https://delphigl.com/forum/

single to string?
https://delphigl.com/forum/viewtopic.php?f=19&t=3093
Seite 1 von 1

Autor:  noeska [ Mi Jul 28, 2004 17:08 ]
Betreff des Beitrags:  single to string?

When i convert a var of type single to var some numbers seem to be added, like

Code:
  1.   dnum:=1.2;
  2.   Writeln(FloatToStr(dnum));


prints:

1.20000004768372

When i convert this back to a single var again wil this produce wrong results in the end? I expect it to print 1.2.

Autor:  Lossy eX [ Mi Jul 28, 2004 17:31 ]
Betreff des Beitrags: 

This is an problem of the single type. Because it's to small for some numbers. Use double instead single and you dosn't have this problem.

PS: You can also convert your Single with the format function. And there your can specify the precission. The resulting text is cut after the 5th zero. When you read it you get the right number. Use '%.6f' for format string.

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/