简体   繁体   English

C#中的科学记数法

[英]Scientific Notation in C#

How do I assign a number that is in scientific notation to a variable in C#? 如何将科学记数法中的数字分配给C#中的变量?

I'm looking to use Plancks Constant which is 6.626 X 10 -34 我想使用Plancks Constant,即6.626 X 10 -34

This is the code I have which isn't correct: 这是我的代码,这是不正确的:

 Decimal PlancksConstant = 6.626 * 10e-34;

You should be able to declare PlancksConstant as a double and multiply 6.626 by 10e-34 like: 您应该能够将PlancksConstant声明为double并乘以6.626乘10e-34,如:

double PlancksConstant = 6.626e-34

Demo 演示

You can set it like this (note the M suffix for the decimal type): 可以像这样设置它(注意decimal类型的M后缀):

decimal PlancksConstant = 6.626E-34M;

But this will effectively be 0 because you can't represent a number with magnitude less than 1E-28 as a decimal . 但这实际上是0,因为你不能用decimal表示幅度小于1E-28的decimal

So you need to use double instead and can just define this: 所以你需要使用double而不是定义它:

double PlancksConstant = 6.626E-34;

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

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