[轉貼] 無條件進位,無條件捨去及四捨五入寫法

2012032813:38

1.無條件進位

double s = 100;
int result = 0;
result = Convert.ToInt16(Math.Ceiling(s / 3));

 

2.無條件捨去

double s = 100;
int result = 0;
result =Convert.ToInt16( Math.Floor(s / 3));

 

3.四捨五入

double s = 110;
double result = 0;
result = Math.Round((s / 3), 2, MidpointRounding.AwayFromZero);