C#

Decimal point handling

Louiey 2019. 9. 23. 11:08

double doubleValue = 0.12345

 

Math.Ceiling(doubleValue); // 올림

Math.Round(doubleValue); // 반올림

Math.Truncate(doubleValue); // 버림

 

Math.Truncate(doubleValue * 10) / 10; // 소수점 첫째 버림

Math.Truncate(doubleValue * 100) / 100; // 소수점 둘째 버림

Math.Truncate(doubleValue * 1000) / 1000; // 소수점 셋째 버림