How to get the last digit of float number in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        float f = 872.1457f;
        string s = f.ToString();
        string fraction_part = s.Substring(s.IndexOf(".") + 1);
         
        Console.WriteLine(fraction_part[fraction_part.Length - 1]);
    }
}




/*
run:

7

*/

 



answered Aug 29, 2019 by avibootz

Related questions

2 answers 203 views
2 answers 150 views
1 answer 217 views
1 answer 156 views
1 answer 194 views
1 answer 151 views
1 answer 142 views
...