Get number of decimal places

Settembre 20th, 2007

Description: ^

Link: http://www.codekeep.net/snippets/0bff2b39-c29d-427f-94dd-5056e7dcacdb.aspx

private int NumberDecimalPlaces(double dec)
        {
            string testdec = Convert.ToString(dec);
            int s = (testdec.IndexOf(".") + 1); // the first numbers plus decimal point
            return ((testdec.Length) - s);     //total length minus beginning numbers and decimal = number of decimal points
        }

  • .NET
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.