close

C#裡面整數除法是不保留餘數的整數結果,所以1/3為0

要得到結果可以 double result = (double)1/3

保留2位小數:double result = Math.Round((decimal)1/3,2);

 

想要四捨五入並保留2位小數:

decimal result = Math.Round((decimal)1 / 3, 2, MidpointRounding.AwayFromZero);
 


arrow
arrow

    Roger 發表在 痞客邦 留言(0) 人氣()