Completely Free .NET word API

Resources » Code Snippets » C# Syntax

Rounding numbers in C#

Updated: Category: C# Syntax
Author: Member Level: GoldPoints: 10

The code below shows how to round number using c# code

Floor will take a double and then convert it to the smallest whole number

System.Console.WriteLine( System.Math.Floor(1.1));
System.Console.WriteLine( System.Math.Floor(1.5));


If you want the largest possible whole number, then you would want Ceiling

System.Console.WriteLine("Ceiling " + System.Math.Ceiling(1.1));
System.Console.WriteLine("Ceiling " + System.Math.Ceiling(1.5));


If you want to round a number to the nearest decimal

System.Console.WriteLine("Round " + System.Math.Round(1.1));
System.Console.WriteLine("Round " + System.Math.Round(1.5));


Did you like this resource? Share it with your friends and show your love!

Responses to "Rounding numbers in C# "

No responses found. Be the first to respond...


Post Comment:

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Subscribe to Subscribers
    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India