Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

258
Vistas
Parse Float string to number rounding off javascript

I have the string "9999999999999.99999" which I covert using Parse Float. But it changes the value to 10000000000000 , is there anyway I can have the get the number same without rounding off?

The input is string and out must be number not string. ex: ParseFloat("9999999999999.99999") = 9999999999999.99999 . So the output should not be string instead number

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Well there is a bit limit to what numbers Javascript can handle (until we get BigInt64 or if you use a library like decimal.js). So since it cannot handle more decimals it just truncates at a point. If you would make a bigger number you would see less decimals. If this then leads to the number being "exacly" 9999999999999.99 in your case javascript will correctly show it as 9999999999999.99 and not 9999999999999.99999 since we only have Number and not float, decimal, int, etc.

parseFloat(9999999999999.99999);
// 9999999999999.99
parseFloat(9999999999999.9999);
// 9999999999999.99
parseFloat(9999999999999.999);
// 9999999999999.998
parseFloat(9999999999999.99);
// 9999999999999.99

Edit: actually it seem to round and not drop.

I hope that explains things.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You could have a look at decimal.js, this allows an arbitrary level of precision to be specified.

const x = new Decimal("9999999999999.99999");
console.log('x:', x.toString())

// Manipulate x
console.log('x * 2:', x.mul(2).toString())
console.log('x / 2:', x.div(2).toString())
<script src="https://cdnjs.cloudflare.com/ajax/libs/decimal.js/9.0.0/decimal.min.js" integrity="sha512-zPQm8HS4Phjo9pUbbk+HPH3rSWu5H03NFvBpPf6D9EU2xasj0ZxhYAc/lvv/HVDWMSE1Autj19i6nZOfiVQbFQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda