如何从Delphi中的格式化float中删除exponent

时间:2011-07-25 21:26:25

标签: delphi

给定像1.00500000274996E-8这样的双重值,如何将其转换为非科学格式,小数点后面的最大位数 - 在这种情况下,8位数字为1.00500000?

转换不应该用零填充,因此2007年将出现在2007年,2012.33和2012.33。

我使用Format,FormatFloat,FloatToStrF尝试过很多组合,但似乎无法获得累积奖金。非常感谢您的帮助。

编辑:我应该澄清一点,我正在尝试将其转换为字符串表示,而不是指数(E)部分。

2 个答案:

答案 0 :(得分:8)

FormatFloat('0.######################', 1.00500000274996E-8)应该可以解决问题。

输出为: 0,0000000100500000274996

它不会输出超过绝对必要的数字。

答案 1 :(得分:2)

在CodeCentral中查看John Herbster的Exact Float to String Routines。也许不完全是你想要的,但可能是一个很好的起点... CC项目的描述:

This module includes
(a) functions for converting a floating binary point number to its *exact* decimal representation in an AnsiString;
(b) functions for parsing the floating point types into sign, exponent, and mantissa; and
(c) function for analyzing a extended float number into its type (zero, normal, infinity, etc.)

Its intended use is for trouble shooting problems with floating point numbers.

他的DecimalRounding惯例也可能很有意义。