How can I do this in C#? Is the only way to use Math.Pow?
Asked
Active
Viewed 5,436 times
1
-
25*10*10*10*10 :) What is wrong with Math.Pow? http://blogs.msdn.com/b/csharpfaq/archive/2004/03/07/why-doesn-t-c-have-a-power-operator.aspx – amit_g Nov 10 '11 at 21:47
-
2Do you need a literal like that, or do you need to perform exponentiation using variables? The former can be done quite simply: 5*(10^4) can be written in C# as `5E4`. – dlev Nov 10 '11 at 21:47
-
See also: http://stackoverflow.com/questions/64639/convert-from-scientific-notation-string-to-float-in-c-sharp – Rick Liddle Nov 10 '11 at 21:48
-
@dlev The `^` symbol in C# is a bitwise XOR, not a power operator. So instead of `5*(10^4)` being 5000 as you suggest, it is actually 70. – Peter Morris Nov 10 '17 at 11:26
2 Answers
9
You can write the literal float constant 5.0e4
(and it works in C, C++, Java, Fortran also).

Basile Starynkevitch
- 223,805
- 18
- 296
- 547
2
You can create your own method that does it for you if you don't wish to use Math.Pow.

Community
- 1
- 1

5StringRyan
- 3,604
- 5
- 46
- 69