14.52-14.49 = 0.0299999?? - Android

By Edwina
at 2011-03-19T03:43
at 2011-03-19T03:43
Table of Contents
※ 引述《newline (漫長的等待與相遇)》之銘言:
: 聽說有的手機算出來是0.29999
: 測試一下你的手機吧
: 聽說MOTO HTC 部份手機會這樣
睡不著寫個Android程式驗證是否是變數資料型態的問題
以14.52 - 14.49當作例子
1. 變數宣告為浮點數 (float)
14.52 - 14.49 = 0.030000687
http://img339.imageshack.us/i/floatv.png/
2. 變數宣告為倍精度浮點數 (double)
14.52 - 14.49 = 0.02999999999999936
http://img15.imageshack.us/i/doublev.png/
3. 變數宣告為整數 (int)
14.52 - 14.49 = 0
http://img843.imageshack.us/i/intd.png/
所以...Google做的計算機,資料型態應該是宣告成double才會造成這個問題XD
無聊的可以下載這個apk去玩玩看...(按menu有設定可以選擇float、double及int)
http://www.multiupload.com/B9YZOL2FR7
我覺得Google根本是懶得理這個問題,多設幾個條件式就可以避免這問題了吧QQ
--
: 聽說有的手機算出來是0.29999
: 測試一下你的手機吧
: 聽說MOTO HTC 部份手機會這樣
睡不著寫個Android程式驗證是否是變數資料型態的問題
以14.52 - 14.49當作例子
1. 變數宣告為浮點數 (float)
14.52 - 14.49 = 0.030000687
http://img339.imageshack.us/i/floatv.png/
2. 變數宣告為倍精度浮點數 (double)
14.52 - 14.49 = 0.02999999999999936
http://img15.imageshack.us/i/doublev.png/
3. 變數宣告為整數 (int)
14.52 - 14.49 = 0
http://img843.imageshack.us/i/intd.png/
所以...Google做的計算機,資料型態應該是宣告成double才會造成這個問題XD
無聊的可以下載這個apk去玩玩看...(按menu有設定可以選擇float、double及int)
http://www.multiupload.com/B9YZOL2FR7
我覺得Google根本是懶得理這個問題,多設幾個條件式就可以避免這問題了吧QQ
--
Tags:
Android
All Comments

By Susan
at 2011-03-19T17:11
at 2011-03-19T17:11

By Candice
at 2011-03-23T12:09
at 2011-03-23T12:09

By Rosalind
at 2011-03-25T21:08
at 2011-03-25T21:08

By Sierra Rose
at 2011-03-29T01:42
at 2011-03-29T01:42

By Yedda
at 2011-04-02T15:33
at 2011-04-02T15:33

By Andrew
at 2011-04-06T07:58
at 2011-04-06T07:58

By Hazel
at 2011-04-07T03:46
at 2011-04-07T03:46

By Hedy
at 2011-04-09T22:13
at 2011-04-09T22:13

By Susan
at 2011-04-10T05:08
at 2011-04-10T05:08

By William
at 2011-04-13T19:18
at 2011-04-13T19:18
Related Posts
核家平安 - 查詢輻射量的好幫手

By Faithe
at 2011-03-18T22:12
at 2011-03-18T22:12
來電走著瞧 who's calling 2.0 上架

By Audriana
at 2011-03-17T21:17
at 2011-03-17T21:17
3/14~3/18 新品優質軟體整理 (18款)

By Eden
at 2011-03-17T00:10
at 2011-03-17T00:10
River's 543 #1 試閱版

By Tom
at 2011-03-15T21:33
at 2011-03-15T21:33
Link2SD 1.5.0現世 ext3/4 fat32 suppo …

By Todd Johnson
at 2011-03-15T20:53
at 2011-03-15T20:53