Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
¿Cómo puedo hacer 2.5% en Javascript?
function rand() { num = Math.floor(Math.random() * 100) if (num == 0 || num == 1) { //2% div.text(num + "you win!") } count += 1 counter.text('count : ' + count) }

¿Cómo puedo hacer 0.5% con Math.random() aquí?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Dado que está utilizando una función de piso y quiere más precisión que 1-100 por ciento, usaría un rango de 1000 números en su lugar.

De esta forma, si la función aleatoria arrojara 0-4, significaría que tiene una probabilidad de 5/1000 = 0,5 %. La función aleatoria devolvería números entre 0 y 999 sin incluir 1000.

 function rand() { num = Math.floor(Math.random() * 1000) if (num < 20) { //2% div.text(num + "you win!") } if (num < 5) { //0.5% div.text(num + "you win!") } count += 1 counter.text('count : ' + count) }
about 4 years ago · Juan Pablo Isaza Report

0

num = Math.round(Math.random() * 100) / 100
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!