คำตอบที่ได้รับเลือกจากเจ้าของกระทู้
ความคิดเห็นที่ 4
- ใช้ Decimal
- ใช้ round
https://paiza.io/projects/tNYryTQLkRQKommceP0qhQ
How To Stop Floating Point Arithmetic Errors in Python
https://medium.com/code-85/how-to-stop-floating-point-arithmetic-errors-in-python-a98d3a63ccc8
สาเหตุคือ binary floating point ไม่สามารถแสดง decimal floaint point ได้แบบตรง ๆ ในบางค่า
บางภาษาจึงเลือกที่จะปัดให้เหลือหลักที่ 17 ...ซึ่งรวมถึง python รุ่นเก่า ๆ ด้วย
https://docs.python.org/3/tutorial/floatingpoint.html
Instead of displaying the full decimal value, many languages (including older versions of Python), round the result to 17 significant digits
ลืมบอกไปว่า python ถือตัวเลขทศนิยมเป็น double precision floating point [Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้CppCon 2015: John Farrier “Demystifying Floating Point"
22,183 views
15 Oct 2015
https://www.youtube.com/watch?v=k12BJGSc2Nc
- ใช้ round
https://paiza.io/projects/tNYryTQLkRQKommceP0qhQ
How To Stop Floating Point Arithmetic Errors in Python
https://medium.com/code-85/how-to-stop-floating-point-arithmetic-errors-in-python-a98d3a63ccc8
สาเหตุคือ binary floating point ไม่สามารถแสดง decimal floaint point ได้แบบตรง ๆ ในบางค่า
บางภาษาจึงเลือกที่จะปัดให้เหลือหลักที่ 17 ...ซึ่งรวมถึง python รุ่นเก่า ๆ ด้วย
https://docs.python.org/3/tutorial/floatingpoint.html
Instead of displaying the full decimal value, many languages (including older versions of Python), round the result to 17 significant digits
ลืมบอกไปว่า python ถือตัวเลขทศนิยมเป็น double precision floating point [Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้CppCon 2015: John Farrier “Demystifying Floating Point"
22,183 views
15 Oct 2015
https://www.youtube.com/watch?v=k12BJGSc2Nc
▼ กำลังโหลดข้อมูล... ▼
แสดงความคิดเห็น
คุณสามารถแสดงความคิดเห็นกับกระทู้นี้ได้ด้วยการเข้าสู่ระบบ
Python 1.9 - 1 ทำไมได้ 0.89999999999 ครับ??? แล้วแก้ยังไง
มันมีวิธีแก้ยัไงครับ