Identify number first local value

Hi Guys,

for a certain checksum task I need to get a number last 'character', or in other words, I need to get the number first local value.

So for example, I have a number (u32), 1739, its first local value is 9. How can I achieve this one?

Currently I convert the number to String, then iter it and get the last character, but it seems to be a tall story this way .. a bit.

Any idea?

You can achieve this by using modulus (%). This will return the remainder of division by 10:

let v = 1379;
assert_eq!(v % 10, 9);

Thanks dude! It's so obvious now.... I was thinking in character positions, and could not break from that concept.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.