Scientific Notation in C#
Asked Answered
S

2

16

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;
Silicone answered 22/1, 2017 at 0:32 Comment(2)
Are you sure you want to use Decimal instead of IEEE-754?Castanon
Use decimal for financial quantities; use double for physical quantities.Rosariorosarium
R
29

You should be able to declare PlancksConstant as a double and multiply 6.626 by 10e-34 like:

double PlancksConstant = 6.626e-34

Demo

Redness answered 22/1, 2017 at 0:41 Comment(0)
D
15

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;
Dialectology answered 22/1, 2017 at 0:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.