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
// C# Program to illustrate the // MathF.Truncate(Single) Method using System; class Geeks { // Main Method public static void Main() { // variables of float type float x1 = 7845.56478452f; float x2 = 12548.3242f; // using method and displaying result Console.WriteLine(MathF.Truncate(x1)); Console.WriteLine(MathF.Truncate(x2)); } } |
Output:
7845 12548
Please Login to comment...