看板 Fortran 關於我們 聯絡資訊
我有一個算式 想要取到小數點5位數 以後捨去或是四捨5入 例如 a=0.123456789 變成 a=0.123450000 或是 a=0.123460000 目前測試程式是 program tt123 implicit none real e,f e=0.123456789 f=e write(*,*) e,f f=f+1000 write(*,*) e,f f=f-1000 write(*,*) e,f end program tt123 結果是 0.1234568 0.1234568 0.1234568 1000.123 0.1234568 0.1234741 Press any key to continue 不是我想要的0.1230000 不知如何改才OK -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.116.77.208 ※ 編輯: jubilee2 來自: 140.116.77.208 (08/30 16:35) ※ 編輯: jubilee2 來自: 140.116.77.208 (08/30 16:36)
awer89:所以要4捨5入還是直接捨去 08/30 16:37
jubilee2:因為我的程式需要疊帶百萬次以上 所以這些誤差會很嚴重 08/30 16:43
jubilee2:直接捨去最好 08/30 16:44
jubilee2:自解..要用INT當中繼站才能轉換成功 08/30 16:53
awer89:*1000後取整數部分即可 08/30 16:58
awer89:取完整數把1000除回去 08/30 16:58
sjgau:fortran 的 default real 是 *4, 精確度只有 5 - 6位 08/30 19:34
sjgau:請改用 real*8, 然後,相關的系統函數呼叫,要使用 dsin() 08/30 19:35