Writing something to the power of?
I'm unsure if I phrased this correctly, but I have to write something to the power of 2.5 and I'm unsure of how to write it in visual studio. Sorry if this is a bit of a basic question, but I'm grateful for any help!
The whole math equation is part of a BMI calculator so i have to write "1.3*weight(kg)/height(m)^2.5".
8 Replies
Math.Pow()
Angius
REPL Result: Success
Result: double
Compile: 260.918ms | Execution: 17.215ms | React with ❌ to remove this embed.
So would I write it like 1.3*(weight)/(height)Math.Pow(2.5)?
No
"X to the power of Y" will be
Math.Pow(X, Y)
Note the comma separating the two parameters
Math.Pow(base, exponent)
Oh! I see, thank you!
$close
Use the /close command to mark a forum thread as answered
For example, for 2^2.5, with .NET 7 or later, you have the flexibility to employ either
float.Pow(2, 2.5f)
or double.Pow(2, 2.5)
, depending on the precision required. In case you're working with earlier versions, utilize MathF.Pow(2, 2.5f)
or Math.Pow(2, 2.5)
accordingly.