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
  • 14,385
  • 29
  • 109
  • 192

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
  • 16,581
  • 13
  • 41
  • 50