我正在项目中使用pint模块。我项目中的对象将数字数据处理为小数。当我将简单品脱单位设置为十进制时,它会起作用:
>>> import pint
>>> from decimal import Decimal as D
>>> ureg = pint.UnitRegistry()
>>> D(10) * ureg.kN
<Quantity(10, 'kilonewton')>
但是,如果我试着增加第二个单位,它就断了。在本例中,建筑千牛顿米:
^{pr2}$我用的是:
>>> a = D(1) * ureg.kN
>>> b = D(1) * ureg.m
>>> unit_kNm = a * b
>>> D(10) * unit_kNm
<Quantity(10, 'kilonewton * meter')>
我明白为什么会这样。我正在寻找一个解决方案来建立品脱我想。在
这是有效的:
还有这个:
^{pr2}$类型转换为
decimal
相关问题 更多 >
编程相关推荐