Powers in Unity - Challenge

Here’s my code to display 2 to the power of 24 for this lesson’s challenge. Did some looking around to get the scientific number to play nice in my Debug.Log!

    void Start()
    {
        float answer = Mathf.Pow(2, 24);
        Debug.Log(answer.ToString("#0"));
    }

Here’s the answer I output!

image

2 Likes

Great work @Dangermau5, adding the format specifier is a great way to tidy up that log message!

Personally, I’m constantly forgetting all the different options and find it useful to bookmark a link to the docs :slight_smile:
https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings

1 Like

Good job, I did the same thing but i used an Int variable

1 Like

Thanks :grin:

I’ve gone ahead and bookmarked those as well, thanks for sharing!

Nice one! I wasn’t able to make an int using Mathf since it’s using floats, I guess I got too lazy to add System to the script :joy:

1 Like

Privacy & Terms