Strings and Floats
I have a slight problem. I am trying to combine Integers with the length of intergers. For example say player 1 score is 1,000. If the player press the a key I want his score to increase by 100. That is simple to do. But If the player press the "s" key I want his score LENGTH to be doubled with extra ZEROS.
For Example. Player score is 1,000
With the "s" key pressed then released
The player score of 1,000 would be 10,000,000 since 8 is the Length of the 1,000 integer doubled with ZEROS. How can I do this with code? I use javascript.
Answer by Scribe · Apr 13, 2016 at 03:28 PM
I cannot currently think of any maths-only solution that does not utilise a while loop, hence here is a solution using ToString()
int score;
score *= Mathf.Pow(10, score.ToString().length);
You may wish to write your own integer-only power function as I am not sure of the efficiency of Mathf.Pow.
Your answer
Follow this Question
Related Questions
how to calculate the angle between two vectors? 6 Answers
Adjusting viewing angle without distortion. 0 Answers
Unity plane constructor bug? 1 Answer
I am showing double on screen and it disappear 1 Answer
How to divide big float 2 Answers