How to extract the int part and the decimal part from float number in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        float f = 872.1457f;
        string s = f.ToString();
        int int_part = (int)f;
        
        Console.WriteLine(int_part);
        Console.WriteLine(s.Substring(s.IndexOf(".") + 1));
    }
}



/*
run:

872
1457

*/

 



answered Aug 29, 2019 by avibootz
...