I want to calculate some percentage that is creating values 0.0034657, 0.000002376876868, 0.00004557600 etc. like this bt in my react project i want to round the ablove values and print those values 0.0034, 0.0000023, 0.000045 like this. Can please someone tell me logic for this or any arithmatic functions for this.
Values : 0.0034657, 0.000002376876868, 0.00002357600
Expected output : 0.0034, 0.0000023, 0.000023
2
Answers
I think you can use the
toFixed
methodlike this:
Here’s a generalised solution, you can pass in any number as the second argument
Haven’t tested with negative values – deal with that yourself if you need toAdded it for you :p