0

Let say I have two floats 0.1788877 and 0.17777231 I only want to convert them in to 0.17 and truncate all the remaining precisions.

For example, FN(0.1788877) === FN(0.17777231) should return TRUE.

What do I do?

newBike
  • 12,989
  • 25
  • 88
  • 158

1 Answers1

0

Number#toFixed(x) returns a string representing the number with the maximum of x digits after the decimal point.

Contverting that string to a number by + will produce the expected result:

const FN=num=>+num.toFixed(2)
FZs
  • 11,931
  • 11
  • 28
  • 41