How to get Last digit of number

前端 未结 8 1232
不思量自难忘°
不思量自难忘° 2021-02-12 11:09

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

<
相关标签:
8条回答
  • 2021-02-12 11:38

    toString() converts number to string, and charAt() gives you the character at a particular position.

    var str = 3232.43;
    lastnum = str.toString().charAt( str.length - 1 );
    alert( lastnum );

    0 讨论(0)
  • 2021-02-12 11:45

    Here is another one using .slice():

    var test = 2354.55;
    var lastDigit = test.toString().slice(-1);
    //OR
    //var lastDigit = (test + '').slice(-1);
    
    alert(lastDigit);

    0 讨论(0)
提交回复
热议问题