Char to Int Unityscript

I am trying to get the first digit of a integer. Example: 21 = 1, 134 = 4 etc.

I am converting the number to a string and getting the number at position 0. If i debug the string, it works fine. However, once I try to convert it to a int again, then the Debug gives me a whole different number. I don’t know what I am doing wrong.

var s : int = 56;
var pos = parseInt(s.ToString()[0]);

This returns the value 53 and not 6. Anyone?

I fixed it using the following code.

var k : String = s.ToString();
var pos = int.Parse(" " + k[k.length-1]);

or you could just mod 10 it… i.e. find the remainer having divided by 10

var pos = s % 10;

(I think that’s how unity handles mod, not tested it but the theory is sound)