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

Solution 1:

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 ^_^

Solution 2:

Here you are:

function generateRandomNumber() {
    var min = 0.0200,
        max = 0.120,
        highlightedNumber = Math.random() * (max - min) + min;

    alert(highlightedNumber);
};

generateRandomNumber();

I understand your real question — you do not know how to get a random number between floating numbers, right? By the way, the answer is passed before.

To play with the code, just click here to jsFiddle.

Update

To get the four first numbers of your decimal, use .toFixed(3) method. I've performed an example here, on jsFiddle.