How do I assign a number that is in scientific notation to a variable in C#?
I'm looking to use Plancks Constant which is 6.626 X 10-34
This is the code I have which isn't correct:
Decimal PlancksConstant = 6.626 * 10e-34;
For scientific notation, you can type either a caret (^) or the letter e followed by a number to indicate an exponent. You can use both positive and negative exponents. For example, to indicate 0.012 , you can enter either of the following expressions: 1.2*10^-2.
Scientific notation is merely a format used for input and output. The 64-bit pattern used for a double inside the computer are the same, no matter what character format was used for input. Here is an example: C:\temp>java DoubleDouble Enter a double: 1.234E+9 value: 1.234E9 twice value: 2.468E9.
Basically in C exponent value is calculated using the pow() function. pow() is function to get the power of a number, but we have to use #include<math. h> in c/c++ to use that pow() function.
You should be able to declare PlancksConstant
as a double
and multiply 6.626 by 10e-34 like:
double PlancksConstant = 6.626e-34
Demo
You can set it like this (note the M
suffix for the decimal
type):
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
.
So you need to use double
instead and can just define this:
double PlancksConstant = 6.626E-34;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With