user2561158 user2561158 - 2 months ago 7
Javascript Question

Get a random number between 0.0200 and 0.120 (float numbers)

I need to create a random number between 0.0200 and 0.120 using JavaScript. How would I do this?

Answer

You could use

(Math.random() * (0.120 - 0.0200) + 0.0200).toFixed(4)

toFixed(n) is used to convert a number into a string, keeping only the "n" decimals.

Hope it helps ^_^

Comments