How to get Last digit of number

前端 未结 8 1249
不思量自难忘°
不思量自难忘° 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:19

    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
    

提交回复
热议问题