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.四捨五入
用法:Math.Round(計算值,小數點第幾位)
double s = 110;
double result = 0;
result = Math.Round((s / 3), 2);
亂馬客之提醒:若是要呈現一般認知的四捨五入需加入第三個參數-MidpointRounding.AwayFromZer
Example:System.Math.Round(1.235 , 2, MidpointRounding.AwayFromZero)
double TodayNav = Convert.ToDouble(m.fundNav);
double YesterdayNav;
YesterdayNav = TodayNav - Convert.ToDouble(m.FundDef);
double percentage = Convert.ToDouble(m.FundDef) / YesterdayNav;
percentage = percentage * 100;
double px = Math.Round((percentage), 2);