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

62
Views
JavaScript converting floating Numbers to Integer overflowing on certain Values

I was trying to implement a form which has a text box that accepts an input from user and converts it to double for sending post request. Example as below.

Image 1

The issue is the input from user is in string format, so I am doing something like, whenever that is onChange then convert it to val/100 and save as double in the state and when displaying on UI display as val*100.All the Values as being displayed correctly but only problem is with Value 7, which overflows to 7.00000001, I am not able to figure out why does it happens. Inside debugger the Value is showing 0.07 and 7 only. See below for the Error.

Error Facing

<TextBox 
   value={getConvertedValue()}
   onChange={changeHandler}   
/>

function getConvertedValue() {
    return (MobxObservable * 100).toString; 
}

changeHandler(event: React.FormEvent, val: string) => {
   // apAction function that sets the value in store.
   setValue(Number(val)/100);
}

Problem - I cannot use Math.round since user wants to enter 1.25 also, toFixed() cannot be used as entering 3 would be then displayed as 3.00 which I doesn't wanted.

What can be the possible solution for this. Tried with available methods but didn't work.

about 4 years ago · Juan Pablo Isaza
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!