Game !

 

 

System.Mafh. 이후 함수를 사용합니다.

 

 

double doubleValue = 0.1234d;

 

Math.Ceiling(doubleValue) // 올림

 

Math.Round(doubleValue) // 반올림

 

Math.Truncate(doubleValue) // 버림

 

 

만약에 소수점 첫째 자리 이하를 버리고 싶다면

 

Math.Truncate(doubleValue * 10) / 10;

 

소수점 둘째 자리 이하

 

Math.Truncate(doubleValue * 100) / 100;

 

소수점 셋째 자리 이하

 

Math.Truncate(doubleValue * 1000) / 1000;

 

.

.

.

식으로 늘려주면 된다.

 

[ 원리 ]

 

원하는 값 : 0.1234 >>>> 0.12

 

1) 0.1234 * 100 = 12.34

2) Truncate 처리 ----> 12

3) 12 / 100 = 0.12

 

 

반올림 / 올림도 같은 기능으로 해주면 된다.

 

 

 

출처:http://yoursyun.tistory.com/category/program/c%23