Javascript - How to get the last digit after decimal number?
javascript
Solution
You could try something like:
var temp = myNum.toString();
var lastNum = parseInt(temp[temp.length - 1]); // it's 2
Edit
You might want to check if your number is an actual decimal, you can do:
var temp = myNum.toString();
if(/\d+(\.\d+)?/.test(temp)) {
var lastNum = parseInt(temp[temp.length - 1]);
// do the rest
}
Problem
e.g., ``` var myNum = 1.208452 ``` I need to get the last digit of myNum after decimal so it is (2)