MathF.Truncate() Method in C# with Examples
In C#, MathF.Truncate(Single) is a MathF class method which is used to compute an integral part of a specified single number or single-precision floating-point number.
Syntax:
public static float Truncate (float x);
Parameter:
x: It is the specified number which is to be truncated and type of this parameter is System.Single.
Return Type: This method only return the integral part of x and discard the fractional part. The type of this method is System.Single.
Example:
CSharp
using System;
class Geeks {
public static void Main()
{
float x1 = 7845.56478452f;
float x2 = 12548.3242f;
Console.WriteLine(MathF.Truncate(x1));
Console.WriteLine(MathF.Truncate(x2));
}
}
|
Last Updated :
21 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...