How to convert float to string with 2 decimal places in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        float f = 83521.976f;
        
        string s = $"{f:F2}";

        Console.Write(s);
    }
}



/*
run:

83521.98

*/

 



answered Feb 12, 2023 by avibootz

Related questions

2 answers 387 views
4 answers 592 views
1 answer 321 views
2 answers 382 views
2 answers 375 views
2 answers 419 views
...