
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
MathF.Truncate() Method in C# with Examples
The MathF.Truncate() method in C# is used to calculate an integral part of a specified single number or single-precision floating-point number.
Syntax
Following is the syntax −
public static float Truncate (float val);
Above, Val is the specified number to be truncated
Example
Let us now see an example to implement the MathF.Truncate() method −
using System; public class Demo { public static void Main(){ float val1 = float.PositiveInfinity; float val2 = float.NegativeInfinity; Console.WriteLine("MathF.Truncate(val1) = "+MathF.Truncate(val1)); Console.WriteLine("MathF.Truncate(val2) = "+MathF.Truncate(val2)); } }
Output
This will produce the following output −
MathF.Truncate(val1) = Infinity MathF.Truncate(val2) = -Infinity
Example
Let us now see another example to implement the MathF.Truncate() method −
using System; public class Demo { public static void Main(){ float val1 = 76.8787f; float val2 = 4646.5656f; Console.WriteLine("MathF.Truncate(val1) = "+MathF.Truncate(val1)); Console.WriteLine("MathF.Truncate(val2) = "+MathF.Truncate(val2)); } }
Output
This will produce the following output −
MathF.Truncate(val1) = 76 MathF.Truncate(val2) = 4646
- Related Articles
- C# Truncate Method
- MathF.Tan() Method in C# with Examples
- MathF.Tanh() Method in C# with Examples
- MathF.Sin() Method in C# with Examples
- MathF.Sinh() Method in C# with Examples
- MathF.Sqrt() Method in C# with Examples
- Decimal.GetHashCode() Method in C# with Examples
- Decimal.GetTypeCode() Method in C# with Examples
- Char.GetHashCode() Method with Examples in C#
- Char.GetTypeCode() Method with Examples in C#
- MathF.Round() Method in C# with Examples
- MathF.Sign() Method in C# with Examples
- MathF.Atanh() Method in C# with Examples
- MathF.Abs() Method in C# with Examples
- MathF.Acos() Method in C# with Examples

Advertisements