C# length of digit after and before point
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
class Program { static void Main(string[] args) { int dec0,dec1; Console.Write("Enter a decimal number (,) :"); //double number = 125.45; double number = Convert.ToDouble(Console.ReadLine()); string[] digits = number.ToString().Split(','); dec0 = digits[0].Length; if (digits.Length == 2) { dec1 = digits[1].Length; } else { dec1 = 0; } Console.WriteLine("Count of digit(s) before point:{0}", dec0); Console.WriteLine("Count of digit(s) after point:{0}", dec1); Console.ReadLine(); } } |