Alex Smith
Alex Smith

Reputation: 19

Can't convert "float" to "mathf" (C#)

I just discovered MathF (wonderful tool). Like any new tool, we're going through some... growing pains. I'm working on unit conversion script. Here's my code. I thought MathF.Pow requires two floats, in this case 10 and 6. But apparently that's frowned upon. Any ideas?

Mathf megagram;


void Start () {
    megagram = Mathf.Pow(10,6);

Upvotes: 1

Views: 72

Answers (2)

Konstantin Zadiran
Konstantin Zadiran

Reputation: 1541

float megagram;

void Start () 
{
    megagram = Mathf.Pow(10f,6f);
}

If you write 6 or 10, compiler thinks that you use Int32. For floats write f suffix - 6f, 10f

Also Mathf.Pow returns float, not a Mathf type

Upvotes: 0

shahkalpesh
shahkalpesh

Reputation: 33476

Mathf.Pow returns a float while you are assigning the return value (float) to megagram (MathF type)

Upvotes: 1

Related Questions