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

170
Views
parseFloat stripping last digits and converting to zeros

I have a scenario where I need to parsefloat 19 digit string to number. e.g. parseFloat("1000000000100000043") gives me 1000000000100000000 but the expected output required is 1000000000100000043

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

0

This is likely a precision overflow error.

The Number data type (but also int and float in other languages) have a finite number of bits available to represent a number. Typically around 15-16 decimal digits worth.

When length of original number in the string exceeds available precision, such number can no longer be represented by the target data type.

In this case the parseFloat function fails silently. If you want to catch this situation you need to add code to check incoming data or use another function, possibly a custom one. Alternatively, you can convert the numeric value back to string and compare it with original to detect a discrepancy.

See also a question regarding double.Parse

about 4 years ago · Juan Pablo Isaza Report

0

You are running into how Javascript numbers are stored. See, e.g., here: https://www.w3schools.com/js/js_numbers.asp

You can use a library like decimal.js to work with large, exact numbers. These libraries store the number as string, but allow you to do mathematical operations.

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!