round function c++1 반올림 함수 반올림 함수는 c에서 기본적으로 지원하지 않는다. 자주 사용되는 관계로 아래와 같이 정리해보았다. /// /// round function /// ex) num= 10.2465, where=3 -> 10.25 /// ex) num=-10.2465, where=3 -> -10.24 /// double round(double num, int where) { double roundedNum = num * pow(10, where-1); roundedNum += 0.5; roundedNum = (roundedNum>0)?floor(roundedNum):ceil(roundedNum); roundedNum *= pow(10, -1 * (where-1)); return roundedNum; } 2011. 1. 10. 이전 1 다음