回文章列表
作者WolfLord.bbs@ptt.cc (呆呆小狼�� �� ��N�� �� ) 看板: linux
標題Re: 奇怪的程式結果
時間批踢踢實業 (2008/03/17 Mon 23:00:52)
※ 引述《coscell.bbs@bbs.cis.nctu.edu.tw (goodman)》之銘言:
: 請教各位前輩下面這段程式:
: #include <stdio.h>
: int main()
: {
:   long int salary=10800000;
:   float tax=0.48;
    double tax=0.48;
:   printf("年薪:\t%ld\n",salary);
:   printf("稅額:\t%f\n",salary*tax);
:   return 0;
: }
這樣應該就可以了,因為浮點數的精密度不足無法表示那麼多的數字位數。
改成倍精度浮點數問題就解決了。

--
~~於是,銀河的歷史又被海賊抹黑了好幾百頁。
      咦?*n的歷史又被*s抹黑了好幾百頁!?
                                                               - A23203 -
 BM4GRM                                                     Harlock WolfLord
★*s      <<上站通知>> -- 我來啦!      

--
※ 發信站: 批踢踢實業坊(ptt.cc) 
◆ From: 220.130.59.234
文章選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻