以10为进制取整

int approximateToNearestMultiple(int number, int multiple)
{
	int nearestMultiple = (number + multiple / 2) / multiple * multiple;
	return nearestMultiple;
}


	int number1 = 404;
	int number2 = 406;
	int multiple = 10;
	int result1 = approximateToNearestMultiple(number1, multiple); -----400
	int result2 = approximateToNearestMultiple(number2,multiple);------410

  下面是lua语言的

 

function roundToNearestTens(number, mulit)
	return math.floor((number +mulit/2)/mulit)* mulit
end


return roundToNearestTens(506,10);-----510

  

posted @ 2024-03-25 14:21  曦花  阅读(8)  评论(0编辑  收藏  举报