1
this.props.credit = '4.10';
 let rate = this.props.credit*100;

I used all parseFloat and Number types along with credit. But the result is always getting as 409.99999999999994. But we know actually the value is 410. Why is getting point difference in reactjs

Lex V
  • 1,414
  • 4
  • 17
  • 35
  • I think this will answer your question https://stackoverflow.com/questions/588004/is-floating-point-math-broken/588014#588014 – Nick Vu Mar 16 '22 at 11:44

2 Answers2

0

This is how javascript behaves and yes it is sometimes quite strange.

You can read more here for example: https://medium.com/@DominicCarmel/understanding-javascripts-weird-decimal-calculations-e65f0e1adefb

Jacob Francke
  • 425
  • 6
  • 23
0

let credit = '4.10';
 let rate =parseFloat(credit*100).toFixed();
 console.log(rate)
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 16 '22 at 12:50