用小数点后的特定数字将double转换为科学计数法 [英] Convert double to scientific notation with specific number after decimal points

查看:151
本文介绍了用小数点后的特定数字将double转换为科学计数法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将double转换为这样的科学计数法:

I want to convert double to scientific notation like this:

-0.00752382528 => -.752383E-1

我可以使用.ToString()还是Regex做到这一点?

can i do this with .ToString() or Regex?

推荐答案

您可以使用标准格式的字符串(科学表示法):

You can either use the standard format string for scientific notation:

(-0.00752382528).ToString("E5")   // returns "-7.52383E-003"

或如果您不希望指数中的前导零,请使用自定义字符串

or if you don't want the leading zeros in the exponent, use a custom string:

(-0.00752382528).ToString("0.00000E0")   // returns "-7.52383E-3"

这篇关于用小数点后的特定数字将double转换为科学计数法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆