Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C# Math Truncate() method is used to round the given number towards zero. It returns the nearest integral value with absolute value less than the argument. In special cases it returns the following:

  • If the argument is NaN, the method returns NaN.
  • If the argument is PositiveInfinity or NegativeInfinity, the method returns same as the argument.

Syntax

public static decimal Truncate (decimal x);

Parameters

x Specify a number.

Return Value

Returns the nearest integral value with absolute value less than the argument.

Example:

In the below example, Truncate() function returns the nearest integral value with absolute value less than the argument.

using System;

class MyProgram {
  static void Main(string[] args) {
   Console.WriteLine(Math.Truncate(2.5));
   Console.WriteLine(Math.Truncate(5.78));
   Console.WriteLine(Math.Truncate(-3.5));
   Console.WriteLine(Math.Truncate(-10.33));
  }
}

The output of the above code will be:

2
5
-3
-10

❮ C# Math Methods