简体   繁体   English

双科学计数格式第十次幂C#

[英]Double scientific notation format 10th power C#

I am having double value = 30308950000; 我的double value = 30308950000;

I want to display it like 3.03x10^10 我想显示为3.03x10^10

How can I achieve it using C#? 如何使用C#实现它?

I have tried 我努力了

double value = 30308950000;
Console.WriteLine(value.ToString("0.###E+0", CultureInfo.InvariantCulture));

output = 3.03E+10 输出= 3.03E+10

I dont want the 3.03E+10 format but 3.03x10^10 . 我不希望使用3.03E+10格式,但希望使用3.03x10^10 Thanks 谢谢

Easy fix: 轻松解决:

double value = 30308950000;
Console.WriteLine(
    value.ToString("0.###E+0", CultureInfo.InvariantCulture)
        .Replace("E-","x10^-")
        .Replace("E+","x10^"));

Shout out to Jon Skeet! 向乔恩·斯凯特大喊! :) :)

Sadly, NumberFormarInfo doesn't provide any ExponentialSign parameter. 可悲的是, NumberFormarInfo没有提供任何ExponentialSign参数。

That it, the Exponential Format Specifier (E) use only NegativeSign, NumberDecimalSeparator and PositiveSign information from the NumberFormarInfo . 就是说, 指数格式说明符(E)仅使用NumberFormarInfo中的 NegativeSign,NumberDecimalSeparator和PositiveSign信息。

To do it "in the pattern" , you have to use your own implementation of ICustomFormatter like here . “按模式进行” ,您必须使用自己的ICustomFormatter实现,如此处所示

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

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