如何用科学计数法格式化数字 [英] How to format a number in scientific notation

查看:100
本文介绍了如何用科学计数法格式化数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我有这个函数返回:3.00000000000E000

So basically I have this function which returns: 3.00000000000E000

function lang():extended;
begin
wynik := 0 ;
   counter := 1;
   temp :=1;
   input := 2;


   for i:= 1 to 4 do
       begin
       for k:= 1 to 4 do
       begin
       if i = k then counter := counter
       else temp := temp * ((input - a[k]) / (a[i] - a[k]));



       end;
       wynik := wynik + temp*f[i];

       temp := 1;
      end;
      Result := wynik;

end;            

但是当我尝试使用FloatToStr在应用程序屏幕上打印它时,我只能得到3.

But when I try to print it on the application screen using FloatToStr, I get only 3.

procedure TFormCalculator.Button1Click(Sender: TObject);
begin
     Edit1.Text := FloatToStr(lang());
end;

如何保留结果的长版本?

How can I keep the long version of the result ?

推荐答案

您必须了解,计算机不会将数字存储为字符串(文本).在这种情况下,您正在使用浮点数.请阅读那篇维基百科文章.(整数要简单得多.)

You have to understand that computers do not store numbers as strings of characters (text). In this case, you are working with floating-point numbers. Please read that Wikipedia article. (Integers are much simpler.)

然后,每次在屏幕上显示数字时,计算机子例程都会从该数字中创建一个字符串(文本).

Then, every time a number is displayed on-screen, a computer subroutine creates a string of characters (text) out of that number.

因此,您始终拥有相同的数字,但是不同的系统会根据该数字创建不同的文本表示形式.

So you always have the same number, but different systems create different textual representations from it.

FloatToStr 将使用简单的默认数字格式.您想要使用12位数字的特定格式(称为科学"或指数").因此,您需要使用支持以下内容的浮点字符串例程:

FloatToStr will use a simple default number format. You want to use a particular format (called "scientific" or "exponential") with 12 digits. So you need to use a float-to-string routine that supports that:

Format('%.12e', [3.0], TFormatSettings.Invariant)

FormatFloat('0.00000000000E+000', 3.0, TFormatSettings.Invariant)

FloatToStrF(3.0, ffExponent, 12, 3, TFormatSettings.Invariant)

请阅读每个功能的文档:

Please read the documentation for each function:

这篇关于如何用科学计数法格式化数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆