[英]How to convert a number into two numbers in the scientific notation?
例如,我在输入中有整数
6456
我想找到将其转换为两个数字的最快方法
6.456 and 1000
使用此方法来确定您的字符串
public static string ConvertExp(int Value)
{
int exp = Math.Abs(Value).ToString().Length -1;
return string.Format("{0} * 10^{1}",( Value / Math.Pow(10 , exp)), exp);
}
并获得 2 个值
public static double[] ConvertExp(int Value)
{
int exp = Math.Abs(Value).ToString().Length -1;
return new double[] { Value / Math.Pow(10, exp), Math.Pow(10, exp) };
}
您不需要算法,只需使用Format 。
Integer 不保存格式信息,但它们可以显示为格式化字符串。 在您的情况下,您需要调用ToString()
并指定要显示的格式: 6456.ToString("e3")
我知道你想用科学记数法显示你的数字。 为此,您可以像这样使用 String.Format 函数:
label1.Text = string.Format("{0:E2}", MyNumber.ToString());
如果你想做相反的事情:
decimal x = decimal.Parse("1.2345E-02", NumberStyles.Float);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.