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.
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.
<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.