在C#中, MathF.Truncate(Single)是MathF类方法,用于计算指定的单个数字或单精度浮点数的整数部分。
句法:
public static float Truncate (float x);
范围:
x: It is the specified number which is to be truncated and type of this parameter is System.Single.
返回类型:此方法仅返回x的整数部分,而舍弃小数部分。此方法的类型为System.Single 。
例子:
// 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));
}
}
输出:
7845
12548