Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the last 2 digits number using jquery

I am entering the digits in the text field as 1528799, can any one tell me how to get last 2 digits of the given number using jquery or javascript

like image 974
lalith458 Avatar asked Dec 25 '13 07:12

lalith458


People also ask

How do I get the last digit of a number in jquery?

To get the last digit of a number:Convert the number to a string and call the slice() method on the string, passing it -1 as a parameter. The slice method will return the last character in the string. Convert the string back to a number to get the last digit.

How do you extract the last two digits of a number?

Last two digits of a number is basically the tens place and units place digit of that number. So given a number say 1439, the last two digits of this number are 3 and 9, which is pretty straight forward.

How do you find the last two digits of a string?

To get the last two characters of a string, call the slice() method, passing it -2 as a parameter. The slice method will return a new string containing the last two characters of the original string. Copied!


1 Answers

Just modulo it with 100

parseInt(document.getElementById("inputField").value, 10) % 100

For example

console.log(1528799 % 100);

will print 99

like image 107
thefourtheye Avatar answered Sep 23 '22 01:09

thefourtheye