How to count of digits after the comma of a double number in C#

1 Answer

0 votes
using System;

public class Program
{
    static int count_digits_after_comma(double d) {
        string dstr = d.ToString();

        return dstr.Length - dstr.IndexOf(".") - 1;
    }
    
    public static void Main()
    {
        double d = 9812347.9085;

        Console.Write(count_digits_after_comma(d));
    }
}



/*
run:

4

*/

 



answered Mar 3, 2024 by avibootz

Related questions

1 answer 121 views
1 answer 136 views
1 answer 121 views
2 answers 212 views
...