[英]Scientific notation sign
I'm writing numbers in a file and they should be looking like this: 我在文件中写数字,它们应该看起来像这样:
5.22226E+00 -2.31833E-01 -9.28221E-01 5.23851E+00 -2.33228E-01 -9.33804E-01
5.25481E+00 -2.34622E-01 -9.39387E-01 5.27116E+00 -2.36016E-01 -9.44969E-01
5.28756E+00 3.65029E-01 9.14477E-01 5.30401E+00 3.66841E-01 9.19016E-01
5.32051E+00 3.68653E-01 9.23556E-01 5.33707E+00 3.70464E-01 9.28095E-01
5.35367E+00 3.72276E-01 9.32634E-01 5.37033E+00 3.74088E-01 9.37174E-01
Instead they are: 相反,它们是:
5.22226E+00 -2.31833E-01 -9.28221E-01 5.23851E+00 -2.33228E-01 -9.33804E-01
5.25481E+00 -2.34622E-01 -9.39387E-01 5.27116E+00 -2.36016E-01 -9.44969E-01
5.28756E+00 3.65029E-01 9.14477E-01 5.30401E+00 3.66841E-01 9.19016E-01
5.32051E+00 3.68653E-01 9.23556E-01 5.33707E+00 3.70464E-01 9.28095E-01
5.35367E+00 3.72276E-01 9.32634E-01 5.37033E+00 3.74088E-01 9.37174E-01
The difference is that I'm not inserting a space when the sign is "+". 区别在于,当符号为“ +”时,我不会插入空格。 How could I do that?
我该怎么办?
The code I use is 我使用的代码是
myNumber.ToString("0.00000E+00", CultureInfo.InvariantCulture);
PadLeft
应该很好地完成了这个技巧:
myNumber.ToString("0.00000E+00", CultureInfo.InvariantCulture).PadLeft(12);
The best approach would be to use conditional formatting : 最好的方法是使用条件格式 :
myNumber.ToString(" 0.00000E+00;-0.00000E+00", CultureInfo.InvariantCulture);
An alternative (more verbose) approach: 另一种(更冗长的)方法:
string s = myNumber.ToString("0.00000E+00", CultureInfo.InvariantCulture);
if (myNumber >= 0)
s = " " + s;
As you can see here , the semicolon sets the formatting according to positive numbers, then negative. 如您在此处看到的,分号根据正数设置格式,然后按负数设置。
myNumber.ToString(" 0.00000E+00;-0.00000E+00", CultureInfo.InvariantCulture);
You can also force a +
to appear if you want, or change the way the -
sign is displayed. 您也可以根据需要强制显示
+
,或更改-
符号的显示方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.