본문 바로가기
[ Program ]/C#

[c#] 현재값과 가장 작으면서 근접하는 5의 배수 가져오기

by 관이119 2022. 11. 11.

 

int tempint = 27;
double result = 0;
if (tempint % 5 != 0)
{
      result = Math.Floor(double.Parse(tempint.ToString()) / 5) * 5;
}
MessageBox.Show(result.ToString());

 

 

5로나눠서 소수점을 버리고 다시 5를 곱하면된다.

댓글