Lets say i have this number: 1.5676556 But i want it to show only 1 (without rounding, lets say i have 0.6, if i use math.round, it will round it to 1)
tnx in advanced.
To remove all numbers from a string, call the replace() method, passing it a regular expression that matches all numbers as the first parameter and an empty string as the second. The replace method will return a new string that doesn't contain any numbers.
substring()" is used to remove the last digit of a number.
Use Math.floor(0.6)
, or if you really want to use string manipulation, String(0.6).split('.')[0]
.
Try this:
0.12345678.toFixed(2) // "0.12"
You are looking for Math.floor if the number greater than 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With