1.無條件進位
double s = 100;
int result = 0;
result = Convert.ToInt16(Math.Ceiling(s / 3));
int result = 0;
result = Convert.ToInt16(Math.Ceiling(s / 3));
2,無條件捨去
double s = 100;
int result = 0;
result =Convert.ToInt16( Math.Floor(s / 3));
double s = 100;
int result = 0;
result =Convert.ToInt16( Math.Floor(s / 3));
3.四捨五入
用法:Math.Round(計算值,小數點第幾位)
double s = 110;
double result = 0;
result = Math.Round((s / 3), 2);
用法:Math.Round(計算值,小數點第幾位)
double s = 110;
double result = 0;
result = Math.Round((s / 3), 2);
若是要呈現一般認知的四捨五入需加入第三個參數-MidpointRounding.AwayFromZer
System.Math.Round(1.235 , 2, MidpointRounding.AwayFromZero)
MSDN說明:http://msdn.microsoft.com/zh-tw/library/ef48waz8(v=VS.100).aspx
留言
張貼留言