新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:pythondecimal是什么
1、概念

decimal意思為十進(jìn)制,這個(gè)模塊提供了十進(jìn)制浮點(diǎn)運(yùn)算支持。主要是用來處理小數(shù)的,針對(duì)與浮點(diǎn)型我們比較熟悉flocat 這個(gè)也可以針對(duì)小數(shù)進(jìn)行處理,但是它會(huì)四舍五入,也可以用到關(guān)于金額,或者需求要求特別精確的方面。
2、優(yōu)點(diǎn)
(1)Decimal所表示的數(shù)是完全精確的。
(2)Decimal類包含有效位的概念,因此1.30 + 1.20的結(jié)果是2.50,保留尾隨零以表示有效位。
3、實(shí)例
與基于硬件的float不同,Decimal具有用戶可更改的精度(默認(rèn)為28位)
>>> from decimal import *
>>> getcontext().prec = 6
>>> Decimal(1) / Decimal(7)
Decimal('0.142857')
>>> getcontext().prec = 28
>>> Decimal(1) / Decimal(7)
Decimal('0.1428571428571428571428571429')以上就是python decimal的介紹,大家在使用進(jìn)制處理數(shù)據(jù)問題時(shí),可以考慮使用decimal函數(shù)來解決。更多Python學(xué)習(xí)推薦:python教學(xué)
(推薦操作系統(tǒng):windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。)
本文標(biāo)題:創(chuàng)新互聯(lián)Python教程:pythondecimal是什么
標(biāo)題鏈接:http://www.5511xx.com/article/cosehes.html


咨詢
建站咨詢
