For example, getting “5” in “256”. The closest I’ve gotten is Math.floor(256/10)), but that’ll still return the numbers in front. Is there any simple way to get what I want or would I have to make a big function for it? Also, for clarity: “n digit” would be defined. Example, getDigit(2,256) would return 5 (second digit)
For example, getting 5 in 256. The closest I’ve gotten is Math.floor(256/10)), but that’ll
Share
or more generally:
where
Nis the number to be extracted, andnis the position of the digit. Note that this counts from 0 starting from the right (i.e., the least significant digit = 0), and doesn’t account for invalid values ofn.