(assuming you mean in the form of a string, not as a number, because IEEE 754 can't have that many significant digits)
must the integer part be 12 digits or can it be 1 or 123? If it can be 12 digits or shorter, then it can be
(Math.floor (Math.random() * Math.pow(10,12))
+ (Math.floor (Math.random() * Math.pow(10,13))
/ Math.pow(10,13)).toString().substring(1))
note that the above could have an issue when the decimal part turns out to be 0
, although the chance is really small. (then the .0
part is gone, although we can use a conditional to add it when it is so). Or we can treat the decimal part 123
not as .0000000000123
but as .123
and use:
(Math.floor (Math.random() * Math.pow(10,12))
+ "." + Math.floor (Math.random() * Math.pow(10,13)))
But it depends whether we care about 123
becoming .123
and 1230
also becoming .1230
because if we do care about it, we can say .123
is the same as .1230
.
Also, if we want to have the form such as 000042987017.0790946977900
as well, so that it is always 12 digit integer and 13 digit decimal, then either we can do zero padding or use something like this:
sample: http://jsfiddle.net/jL4t4/1/
var i, s = "";
for (i = 0; i < 26; i++) {
s += (i === 12) ? "." : Math.floor(Math.random() * 10);
}