如何获得最后一位数字 [英] How to get Last digit of number
本文介绍了如何获得最后一位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用jquery提取Number值的最后(结束)数字。
因为我必须检查数字的最后一位是0还是5.所以如何得到小数点后的最后一位数
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
对于Ex。
var test = 2354.55
现在如何使用jquery从这个数值中得到5。
i尝试 substr ,但这只适用于字符串而非数字格式
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
如果我使用 var test =2354.55;
然后它会起作用但如果我使用 var test = 2354.55
然后它不会。
then it will work but if i use var test = 2354.55
then it will not.
推荐答案
试试这个:
var test = 2354.55;
var lastone = test.toString().split('').pop();
alert(lastone);
这篇关于如何获得最后一位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文