什么是Java的BigDecimal的Python? [英] What is the python for Java's BigDecimal?

查看:227
本文介绍了什么是Java的BigDecimal的Python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,当我们计划金钱时,建议使用BigDecimal类来获得金钱。 python中有类似的东西吗?我想要一个可以有货币和汇率的面向对象的东西,这样做了吗?

我将钱存为美分整数(我认为),并将其乘以100来获得美元,但我也有外币,因此当物品有价格时,按价格排序的上市列表变得不方便不同的货币,甚至被列为每小时或每件产品的价格。所以理想情况下,如果定价是每小时或每件商品,我希望一个班级在python中拥有汇率,货币和定价类型。



所以我想我在找一个价格类,而不是 money class,是否有这样的事情?我正在编程的gae没有十进制数据类型,所以我可以使用一个表示分数的整数,或者像我自己实现的十进制表示那样创建一些东西。 java.math.BigDecimal decimal.Decimal 。您甚至可以阅读文档了解更多信息。 mpmath 是一个用于多精度浮点运算的纯Python库。

In Java, when we program money it is recommended to use the class BigDecimal for money. Is there something similar in python? I would like something object-oriented that can have a currency and an exchange rate, has that been done?

I store money as integers of cents (I think) and multiply with 100 to get dollars but I also have foreign currency so listing listing ordered by price becomes inconvenient when articles have different currencies and even are listed as price per hour or per item. So ideally I would like a class for money in python that has exchange rate, currency and what type of pricing it is, if the pricing is per hour or per item.

So I suppose I'm looking for a priceclass and not a moneyclass, is there such a thing already? The gae I'm programming at doesn't have decimal data type so I can use an integer representing just the fraction or invent something like an own decimal representation where I implement it.

解决方案

The java.math.BigDecimal in Java's equivalent is decimal.Decimal in Python. You can even go through the documentation for more. mpmath is a pure-Python library for multi-precision floating-point arithmetic.

这篇关于什么是Java的BigDecimal的Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆