Generate a big random float jquery/JavaScript -


this question has answer here:

i need generate 12 digit , 13 decimals float value this:

123438767411.238792938 

how can in javascript/jquery? possible generate code using javascript?

i trying this:

v1 = math.floor((math.random()*10000000000)+1); v2 = math.floor((math.random()*100000000)+1); v = v1.tostring() + "." + v2.tostring(); 

but not working!

(assuming mean in form of string, not number, because ieee 754 can't have many significant digits)

must integer part 12 digits or can 1 or 123? if can 12 digits or shorter, 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 above have issue when decimal part turns out 0, although chance small. (then .0 part gone, although can use conditional add when so). or can treat decimal part 123 not .0000000000123 .123 , use:

(math.floor (math.random() * math.pow(10,12))      + "." + math.floor (math.random() * math.pow(10,13))) 

but depends whether care 123 becoming .123 , 1230 becoming .1230 because if care it, can .123 same .1230.

also, if want have form such 000042987017.0790946977900 well, 12 digit integer , 13 digit decimal, either can 0 padding or use this:

sample: http://jsfiddle.net/jl4t4/1/

var i, s = "";  (i = 0; < 26; i++) {     s += (i === 12) ? "." : math.floor(math.random() * 10); } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -