简体   繁体   English

将指数转换为字符串

[英]Convert Exponential number to string

I am using the below code to convert exponential number to string. 我正在使用以下代码将指数数字转换为字符串。 It's working partially. 它正在部分工作。 Please help me to do this. 请帮我做到这一点。

This is my Exponential number is 4.00658E+16 //In text format '40065812120130567' 这是我的指数编号是4.00658E + 16 //以文本格式'40065812120130567'

The below code convert this number to 40065812120130600. Some times it didn't convert the last two digits. 下面的代码将此数字转换为40065812120130600。有些时候它没有转换最后两位数字。 Please help me to solve this issue. 请帮我解决这个问题。

 decimal device;
 string dvc_id = Convert.ToString(dt.Rows[i][4]);//dt.Rows[i][4]

 decimal.TryParse(dvc_id, NumberStyles.Any, CultureInfo.InvariantCulture, out device);
 dvc_id = device.ToString();

The number 4.00658121201306E+16 , which you say you are using, is NOT the same as 40065812120130567 . 您说正在使用的数字4.00658121201306E+1640065812120130567 The last two digits are dropped because the exponential form does not have those digits as part of the number. 最后两位数字被删除,因为指数形式没有这些数字作为数字的一部分。

The last two digits aren't stored at all in that number. 该数字根本不存储后两位。 All exponential notation does is tell where the decimal point should be, essentially. 本质上,所有指数表示法都会告诉小数点应在哪里。 What you see is what you get in terms of the precision of the value, and you're not giving the program any digits after the six. 您所看到的是从值的精度上得到的结果,并且您没有在程序后面的六位数字。 Hence, it won't give you any digits after the six. 因此,它不会给您六位数之后的任何数字。

你可以尝试下面的代码吗

var num = Decimal.Parse("4.00658E+16", System.Globalization.NumberStyles.Float);

建议使用BigInteger类:

var number = BigInteger.Parse("400658121201306000000000000");

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

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