How to get the first digit after the decimal point of a float number in C#

2 Answers

0 votes
using System;

class Program
{
    static void Main() {
        float f = 872.2459f;
        string s = f.ToString();
 
        Console.Write(s.Substring(s.IndexOf(".") + 1, 1));
    }
}



/*
run:

2

*/

 



answered Aug 29, 2019 by avibootz
0 votes
using System;

class Program
{
    static void Main() {
        float f = 23.7846f;

        Console.Write((int)(Math.Floor(Math.Abs(f) * 10)) % 10);
    }
}



/*
run:

7

*/

 



answered Aug 31, 2019 by avibootz
...