Engineering notation in C#?

前端 未结 9 2181
离开以前
离开以前 2020-12-03 17:44

Is there any code out there (or a built-in function) which allows outputting a floating point number in engineering notation?

For example, 1.5e-4 would

9条回答
  •  眼角桃花
    2020-12-03 18:11

    Rather than subclassing, I'd take advantage of the fact that Double implements IFormattable and write an IFormatProvider that formats the number. Then I'd have code that looks similar to:

    double d = 123.45;
    Console.WriteLine(d.ToString(null, new MyCustomFormat()));
    

提交回复
热议问题