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

314
Vistas
How does the V8 toString(radix) method in Google Chrome or in Node.js handle floating point numbers?

The method works clearly with integer numbers, e.g.

(25).toString(2)
= '11001'

(25).toString(16)
= '19'

(25).toString(36)
= 'p'

But entering floats results in

(0.1).toString(2)
= '0.0001100110011001100110011001100110011001100110011001101'

(0.1).toString(16)
= '0.1999999999999a'

(0.1).toString(36)
= '0.3lllllllllm'

V8 is said to be an open-source engine. However, I cannot find the exact implementation of this method in the repository in order to understand it. How does the function handle floats?

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

0

(V8 developer here.)

@pilchard's link is right; more specifically the function you're looking for is DoubleToRadixCString.

The observation that 0.1 (decimal) is a non-terminating fraction in its binary representation (which is, of course, how doubles are stored inside computers) is a nice illustration of the underlying reason why 0.1 * 3 == 0.30000000000000004: the non-terminating fractions are necessarily cut off at some point, which constitutes a rounding error, and some operations make these rounding errors visible. It's the binary equivalent of a similar effect in decimal: when you represent 1/3 as "0.333333" (arbitrarily choosing 6 digits as the represented length, but if you only cut off after 100 digits that wouldn't really change anything), and multiply that by 3, you get "0.999999", not 1.

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