How to round a decimal to 2 decimal places in C#

3 Answers

0 votes
using System;

class Program
{
    static void Main() {
        decimal dec = 356.8719533m;
        
        dec = decimal.Round(dec, 2, MidpointRounding.AwayFromZero);
    
        Console.Write(dec);
    }
}



/*
run:

356.87

*/

 



answered Sep 4, 2019 by avibootz
0 votes
using System;

class Program
{
    static void Main() {
        decimal dec = 356.8719533m;

        dec = Math.Round(dec, 2);
    
        Console.Write(dec);
    }
}



/*
run:

356.87

*/

 



answered Sep 4, 2019 by avibootz
0 votes
using System;

class Program
{
    static void Main() {
        decimal dec = 356.8719533m;

        Console.Write(dec.ToString("0.##"));
    }
}



/*
run:

356.87

*/

 



answered Sep 4, 2019 by avibootz

Related questions

4 answers 122 views
1 answer 172 views
2 answers 242 views
3 answers 300 views
3 answers 324 views
3 answers 216 views
2 answers 163 views
...