English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

#include
#include
int main()
{
float *****;
*****=87.1;
printf("%f",*****);
system("pause");
return 0;
}
為什麼我跑出來是87.099998
如果我是打%4.3f的話
才是87.100

2006-11-12 20:07:44 · 4 個解答 · 發問者 Otaku Man 1 in 電腦與網際網路 程式設計

4 個解答

%4.3f ... 代表你要取到小數第三位.... prinf() 處理是4捨5入方式產生進位

2006-11-13 01:15:39 補充:
*****; 不要這樣命名變數最好是有意義的變數名稱

2006-11-13 01:40:00 補充:
小娟Sara 怎樣奇怪數字??87.1 其實在記憶體中沒辦法用二進制表示0.1... 會有誤差他應該是printf()印出來87.1 是經過進位結果~~double x= 87.1;printf("%.14f",x); 應該是87.09999999999...double x= 87.125;printf("%.14f",x); 87.125000000000...因為0.125 可以用二進制表示它

2006-11-12 20:14:26 · answer #1 · answered by ? 1 · 0 0

有關版大與小娟的疑問,參
http://tw.knowledge.yahoo.com/question/?qid=1206111305447

http://tw.knowledge.yahoo.com/question/?qid=1106111503998

2006-11-16 03:07:56 · answer #2 · answered by ? 7 · 0 0

there is no 0.1 in floating point. So unless you round it up to one-tenth, 0.099999999...is same as 0.1. If you run the debugger and check the value of 0.1, you will see 0.099999....too.

2006-11-13 00:59:32 · answer #3 · answered by ? 2 · 0 0

這個問題…之前老師好像有說過..不過忘記為什麼了... @﹏@
變數宣告用double x,x=87.1,這樣printf("%f",x); 就會印出87.100000了
不過double宣告..如果印%.14f的話..也是會變成奇怪的數字...
可能存數值的時候才能存到第幾位吧 @﹏@||

變數名稱設*****應該是直接不能執行吧 @@ 所以他應該只是把名稱用*代替而已
主要問題是為什麼印出來不是87.100000…真的知道的高手來解答吧 @@

2006-11-15 01:39:10 補充:
double x=87.1,用%.15f印的時候→87.099999999999994用%.16f印的時候→87.0999999999999940那為什麼會這樣呢? @_@ 這個應該是奇怪的數字吧…(回答過的人還會回來看嗎 @﹏@|||)

2006-11-12 20:26:12 · answer #4 · answered by ? 5 · 0 0

fedest.com, questions and answers