勤奋菜鸟的天堂

导航

2013年2月1日 #

除法运算小数点的问题

摘要: 在c#中int与int的除法默认不保留小数点,floatresult = 1010 / 100; // result = 10;需要保留小数点,可以如下floatresult = 1010f或者(float)1010F / 100;如果需要限定小数点的位数,则可以使用Math.Round():floatresult = Math.Round((float)x/ y,2); 后面的2表示保留小数点后2位小数 阅读全文

posted @ 2013-02-01 14:50 勤奋的菜鸟 阅读(339) 评论(0) 推荐(0) 编辑