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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# Program to illustrate the
// MathF.Truncate(Single) Method
using System;
  
class Geeks {
  
    // Main Method
    public static void Main()
    {
  
        // varibles 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));
    }
}

chevron_right


Output:

7845
12548


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.