Round down a number : Round « Development Class « C# / C Sharp





Round down a number

Round down a number
using System;
using System.Data;
using System.Text.RegularExpressions;

class Class1{
        static void Main(string[] args){
      Console.WriteLine(RoundDown(.4));
      Console.WriteLine(RoundDown(.5));
      Console.WriteLine(RoundDown(.6));
      Console.WriteLine(RoundDown(1.4));
      Console.WriteLine(RoundDown(1.5));
      Console.WriteLine(RoundDown(1.6));
      Console.WriteLine(RoundDown(2.4));
      Console.WriteLine(RoundDown(2.5));
      Console.WriteLine(RoundDown(2.6));
      Console.WriteLine(RoundDown(3.4));
      Console.WriteLine(RoundDown(3.5));
      Console.WriteLine(RoundDown(3.6));
        }
    public static double RoundDown(double valueToRound)
    {
      double floorValue = Math.Floor(valueToRound);
      if ((valueToRound - floorValue) > .5)
      {
        return (floorValue + 1);
      }
      else
      {
        return (floorValue);
      }
    }
}


           
       










Related examples in the same category

1.Rounding a Floating Point ValueRounding a Floating Point Value
2.Round up a numberRound up a number