How to get Last digit of number

2020-06-08 08:34发布

How to extract last(end) digit of the Number value using jquery. because i have to check the last digit of number is 0 or 5. so how to get last digit after decimal point

For Ex. var test = 2354.55 Now how to get 5 from this numeric value using jquery. i tried substr but that is only work for string not for Number format

Like if i am use var test = "2354.55";

then it will work but if i use var test = 2354.55 then it will not.

7条回答
别忘想泡老子
2楼-- · 2020-06-08 09:03

you can just convert to string

var toText = test.toString(); //convert to string
var lastChar = toText.slice(-1); //gets last character
var lastDigit = +(lastChar); //convert last character to number

console.log(lastDigit); //5
查看更多
登录 后发表回答