简体   繁体   English

如何将大数字格式化为字符串以在Delphi中显示

[英]How to format a big number into string for display in Delphi

I have a double type big number, say 1111111111111110000000000000.000. 我有一个双1111111111111110000000000000.000.型大数字,例如1111111111111110000000000000.000. How to format it to string for display in Delphi? 如何将其格式化为字符串以在Delphi中显示?

I've tried FloatToStr and FormatFloat , but I receive the Scientific Notation which is not what I want. 我已经尝试过FloatToStrFormatFloat ,但是我收到的科学FloatToStr法不是我想要的。

Using the System.Str conversion works: 使用System.Str转换可以:

var
  d: Double;
  s: String;
begin
  d := 1111111111111110000000000000.000;
  Str(d:0:3,s);
  WriteLn(s);
end;

Outputs: 1111111111111109950000000000.000 输出:1111111111111109950000000000.000

Note: double precision has not the precision to exactly hold the digits you are trying to input. 注意:double precision不能精确保留要输入的数字。

Normally in that case you would not show all digits, since this can give the impression that they all are accurate. 通常情况下,您不会显示所有数字,因为这会给人留下所有数字都是准确的印象。 This is why the scientific notation is prefered. 这就是为什么首选科学表示法的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM