→ stupid0319:如果存在記憶體是Double那應該直接減掉0.00078就可以了 05/19 17:41
→ stupid0319:如果存的是文字,直接把7那一位改成\0 05/19 17:41
→ angleevil:(double)((int)(x * 1000) / 1000) 05/19 17:44
→ firejox:%.3f.... 05/19 17:50
→ sand1050: x=floor(x*1000)/1000; 05/19 18:08
→ firejox:scanf("%.3lf",&x); //l != 1... 05/19 18:28
→ sand1050:fscanf(檔案指標,"%lf",&x); x=floor(x*1000)/1000; 05/19 22:32
→ olozil:<math.h> RoundTo() 05/20 00:10
推 avonasac0800:%.3f不是比較方便嗎..?? 05/20 00:47
→ xatier:double要用lf吧? scanf()的時後 05/20 07:47
推 purpose:C99 規定 小寫l 加在 f 時,沒有效果,等同於 %f 05/20 08:28
→ purpose:不遵從 C99,有可能是在指定 long double。%Lf 保證 long 05/20 08:28
→ purpose:double。VC的long double等於double,但gcc的則是12 Bytes 05/20 08:29
感謝以上大大回答
(double)((int)(x * 1000) / 1000) 我也有使用,只是讀取數值過大,int會溢位
EX: 1234567.12345 <===這種就溢位了
另外感謝 sand大 floor 第一次聽過,也很好用!!!
※ 編輯: lovecomic 來自: 140.115.110.234 (05/20 09:22)
→ angleevil:~"~沒考慮,double dInt;modf(x*1000,&dInt); 05/20 09:40
→ angleevil:x = dInt / 1000;這樣也可以,只是比較慢 05/20 09:41
→ xatier:scanf, on the other hand, accepts pointers, and no such 05/20 11:25
→ xatier: promotions apply. Storing into a float (via a pointer) 05/20 11:25
→ xatier:is very different from storing into a double, so scanf 05/20 11:25
→ xatier:distinguishes between %f and %lf. C FAQ 說要分耶 <囧> 05/20 11:26
推 purpose:原來如此,x大是對的。我一開始只看了 printf 的說明寫 05/20 11:39
→ purpose:沒有效果。但是 scanf 的說明沒看,上面則是寫有區別沒錯 05/20 11:40
→ purpose:一直以為兩邊通用,長見識了,感謝 05/20 11:40
推 xatier:-) 05/20 11:58
→ james732:我也以為printf跟scanf是通用的...XD 05/20 11:59
推 purpose:以前都沒注意到呢,太粗心了 05/20 13:55