How to truncate a number from left in C#

1 Answer

0 votes
using System;

public class Program
{
	private static int truncate_left(int num) {
		int total = (int)Math.Log10(num); // total - 1 = 3

		int first_digit = num / (int)Math.Pow(10, (total));

		return num - first_digit * (int)Math.Pow(10, (total));
	}

	public static void Main(string[] args)
	{
		int num = 7483;

		Console.Write(truncate_left(num));
	}
}






/*
run:
       
483
       
*/

 



answered Jan 11, 2024 by avibootz

Related questions

1 answer 116 views
1 answer 140 views
1 answer 109 views
1 answer 149 views
1 answer 112 views
112 views asked Jan 11, 2024 by avibootz
1 answer 94 views
1 answer 118 views
118 views asked Jan 10, 2024 by avibootz
...