+ 1

How to convert the last digit in a number into a string??

4356 👉 six

24th Feb 2017, 7:45 PM
‏‪Amal Ateya‬‏
‏‪Amal Ateya‬‏ - avatar
2 Respostas
+ 2
You can convert the entire number into a string and then get the last character of that string and convert it back to a string. You didn't specify a language so all I can give is a general explanation that will work with most languages. 4356 -> "4356" -> '6' -> "6"
24th Feb 2017, 8:00 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Now that you have specified C# as the language: class Program { static void Main() { int myInt = 4356; String x = myInt.ToString().Substring(myInt.ToString().Length-1); Console.WriteLine(x); } }
24th Feb 2017, 10:16 PM
ChaoticDawg
ChaoticDawg - avatar