C#의 Decimal.Truncate() 메서드는 지정된 Decimal의 정수를 반환하는 데 사용됩니다. 소수점 이하 자릿수는 무시됩니다.
구문
다음은 구문입니다 -
public static decimal Truncate (decimal val);
위의 Val은 잘라낼 10진수입니다.
예
이제 Decimal.Truncate() 메서드를 구현하는 예를 살펴보겠습니다. -
using System;
public class Demo {
public static void Main(){
Decimal val = 6576.876m;
Console.WriteLine("Decimal value = "+val);
ulong res = Decimal.ToUInt64(val);
Console.WriteLine("64-bit unsigned integer = "+res);
Decimal val2 = Decimal.Truncate(val);
Console.WriteLine("Integral digits of the decimal = "+val2);
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
Decimal value = 6576.876 64-bit unsigned integer = 6576 Integral digits of the decimal = 6576
예
이제 Decimal.Truncate() 메서드를 구현하는 또 다른 예를 살펴보겠습니다. -
using System;
public class Demo {
public static void Main(){
Decimal val = 28676.935m;
Console.WriteLine("Decimal value = "+val);
Decimal val2 = Decimal.Truncate(val);
Console.WriteLine("Integral digits of the decimal = "+val2);
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
Decimal value = 28676.935 Integral digits of the decimal = 28676