casas decimais

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public static void Main()
	{
		decimal teste = 9.23141233112342m;
		Console.WriteLine(casasDecimais(teste));
		teste = 1.32m;
		Console.WriteLine(casasDecimais(teste));
		teste = 1.32322342m;
		Console.WriteLine(casasDecimais(teste));
	}
	
	public static int casasDecimais(decimal d)
	{
		int res = 0;
		while(d != (long)d)
		{
			res++;
			d = d*10;
		}
		return res;
	}
}
;