living in my life (史蘭諾系統整合服務)
2011年6月11日 星期六
[C#]使用 double除法取出有小數位數的餘數(Use double division has taken out the remainder of decimal places)
問題
使用 double除法取出有小數位數的餘數
int x=10;
double y=1/x;
求出來會是0歐!
注意了,因為x型別是int(整數型別),所以求出來的值會自動轉型
因此若要求出0.1,要改寫如下
解決方法
double y=1/(double)x;
就可求出0.1囉!!
沒有留言:
張貼留言
‹
›
首頁
查看網路版
沒有留言:
張貼留言