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

220
Views
Número de precio entero para flotar Javascript

Estoy interactuando con una API y devuelve el precio como un número entero, por ejemplo:

99.59 se devuelve desde la API así: 9959

60.00 se devuelve así 6000

252.90 se devuelve así 25290

Me encantaría una función que tome el número entero y lo haga flotar exactamente como la anterior, por lo que 25290 debería ser 252,90 y 9959 debería ser 99,59

Cualquier ayuda es muy apreciada.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puedes usar algo como esto.

 const formatNumber = (value, precision = 2) => { return (value / 100).toFixed(precision); } console.log(formatNumber(60000, 3)); console.log(formatNumber(2529));

Y use esa función formatNumber para formatear.

Como, formatNumber(6000, 3) y devolverá algo así como 60.000 .

about 4 years ago · Santiago Trujillo Report

0

Podría tomar una función y convertir el valor en una picadura, mantener la longitud y agregar un punto.

 const format = integer => integer .toString() .padStart(3, 0) .replace(/(?=..$)/, '.'); console.log(format(0)); console.log(format(9)); console.log(format(19)); console.log(format(9959));

about 4 years ago · Santiago Trujillo 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!