久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

round() 似乎沒有正確舍入

round() doesn#39;t seem to be rounding properly(round() 似乎沒有正確舍入)
本文介紹了round() 似乎沒有正確舍入的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

round() 函數(shù)的文檔說明您通過它是一個數(shù)字,小數(shù)點后的位置要四舍五入.因此它應該這樣做:

The documentation for the round() function states that you pass it a number, and the positions past the decimal to round. Thus it should do this:

n = 5.59
round(n, 1) # 5.6

但是,實際上,舊的浮點怪異現(xiàn)象逐漸出現(xiàn),您會得到:

But, in actuality, good old floating point weirdness creeps in and you get:

5.5999999999999996

出于 UI 的目的,我需要顯示 5.6.我在互聯(lián)網(wǎng)上一探究竟,發(fā)現(xiàn)了一些 文檔取決于我對 Python 的實現(xiàn).不幸的是,這發(fā)生在我的 Windows 開發(fā)機器和我嘗試過的每臺 Linux 服務器上.另見此處.

For the purposes of UI, I need to display 5.6. I poked around the Internet and found some documentation that this is dependent on my implementation of Python. Unfortunately, this occurs on both my Windows dev machine and each Linux server I've tried. See here also.

沒有創(chuàng)建自己的圓形庫,有什么辦法解決這個問題嗎?

Short of creating my own round library, is there any way around this?

推薦答案

我無法控制它的存儲方式,但至少格式可以正常工作:

I can't help the way it's stored, but at least formatting works correctly:

'%.1f' % round(n, 1) # Gives you '5.6'

這篇關于round() 似乎沒有正確舍入的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

Python 3 Float Decimal Points/Precision(Python 3 浮點小數(shù)點/精度)
Converting Float to Dollars and Cents(將浮點數(shù)轉換為美元和美分)
What are some possible calculations with numpy or scipy that can return a NaN?(numpy 或 scipy 有哪些可能的計算可以返回 NaN?)
Python float to ratio(Python浮動比率)
How to manage division of huge numbers in Python?(如何在 Python 中管理大量數(shù)字的除法?)
mean from pandas and numpy differ(pandas 和 numpy 的意思不同)
主站蜘蛛池模板: 午夜美女福利视频 | 成人免费视频一区二区 | 精品一区在线 | 国产6区| 日日干夜夜爽 | 日韩欧美在线视频观看 | 国产一级二级视频 | 日韩视频在线观看免费 | 日韩av专区 | 一级黄色网 | 九九久久精品视频 | 两性免费视频 | 蜜桃av一区 | 一区二区三区在线看 | 日日爽天天 | 在线观看免费av网站 | 欧美亚洲国产日韩 | 美日韩在线视频 | 国产日韩欧美 | av免费资源 | 黄色免费小视频 | 精品少妇v888av | 99久久精品一区二区成人 | 波多野结衣乳巨码无在线观看 | 伊人网综合 | 久久免费国产视频 | 国产又粗又大又硬 | av中文网 | 精久久久久| 婷婷色在线| 午夜一级片 | 可以看的毛片 | 福利视频网址导航 | 色综合一区二区 | 亚洲欧美日韩一区二区三区四区 | 日韩免费大片 | 欧美另类综合 | 日韩免费观看 | 日本在线免费观看视频 | 久久香蕉网 | 亚洲午夜在线观看 |