Some problem about ceil()
古いコメントを表示
The result of ceil(215.08/0.152) is 1416. However, it should be 1415 in practice. This makes a further mistake for the latter calculation. How can I avoid this problem?
2 件のコメント
Star Strider
2017 年 7 月 12 日
Your image did not appear.
Using round instead of ceil returns 1415.
Edmond Dantes
2017 年 7 月 12 日
採用された回答
その他の回答 (1 件)
Guillaume
2017 年 7 月 12 日
As others have commented, this is normal behaviour for computers using ieee floating points. Switching to some non-binary storage system (e.g. .Net System.Decimal) is an option. Alternatively, you can round your result to something with less decimal, then use ceil on that:
ceil(round(215.08/0.152, 8))
While the above works for this particular case, I'm sure that some counterexamples could be found.
カテゴリ
ヘルプ センター および File Exchange で Common Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!