How to round up a double value to 2 decimal places in C#

3 Answers

0 votes
using System;

public class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine(Math.Ceiling(199.183));
        Console.WriteLine(RoundUp(199.183, 2));
    }
    
    public static double RoundUp(double d, int places) {
        double multiplier = Math.Pow(10, Convert.ToDouble(places));
 
        return Math.Ceiling(d * multiplier) / multiplier;
    }
}


/*
run:

200
199.19

*/

 



answered Jan 17, 2017 by avibootz
edited May 15, 2025 by avibootz
0 votes
using System;

public class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine(Math.Ceiling(199.183));
        Console.WriteLine(Math.Ceiling(199.183 * 100) / 100);
    }
}


/*
run:

200
199.19

*/

 



answered Jan 17, 2017 by avibootz
edited May 15, 2025 by avibootz
0 votes
using System;

public class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine(Math.Ceiling(199.183));
        Console.WriteLine(0.01 * Math.Ceiling(100 * 199.183));
    }
}


/*
run:

200
199.19

*/

 



answered Jan 17, 2017 by avibootz
edited May 15, 2025 by avibootz

Related questions

4 answers 122 views
1 answer 55 views
1 answer 51 views
1 answer 62 views
3 answers 325 views
3 answers 211 views
1 answer 137 views
...