C# Math Truncate(Double)

Description

Math Truncate(Double) calculates the integral part of a specified double-precision floating-point number.

Syntax

Math.Truncate(Double) has the following syntax.


public static double Truncate(
  double d
)

Parameters

Math.Truncate(Double) has the following parameters.

  • d - A number to truncate.

Returns

Math.Truncate(Double) method returns The integral part of d; that is, the number that remains after any fractional digits have been discarded, or one of the values listed in the following table. d Return value NaN NaN NegativeInfinity NegativeInfinity PositiveInfinity PositiveInfinity

Example

The following example calls the Truncate(Double) method to truncate both a positive and a negative Double value.


using System;//from  w  w  w.ja  v  a 2s .  co m

public class MainClass{
  public static void Main(String[] argv){  
    double floatNumber;
    
    floatNumber = 32.7865;
    // Displays 32      
    Console.WriteLine(Math.Truncate(floatNumber));
    
    floatNumber = -32.9012;
    // Displays -32       
    Console.WriteLine(Math.Truncate(floatNumber));
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version