• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python money.Money类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中money.Money的典型用法代码示例。如果您正苦于以下问题:Python Money类的具体用法?Python Money怎么用?Python Money使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Money类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: testMixedAddition

	def testMixedAddition(self):
		fiveBucks = Money.dollar(5)
		tenFrancs = Money.franc(10)
		bank = Bank()
		bank.addRate('CHF', 'USD', 2)
		result = bank.reduce(fiveBucks.plus(tenFrancs), 'USD')
		self.assertEquals(Money.dollar(10), result)
开发者ID:lenin,项目名称:TDDbyExample,代码行数:7,代码来源:tests.py


示例2: test_return_the_difference_between_the_two_same_nationality_money

    def test_return_the_difference_between_the_two_same_nationality_money(self):
        money_yen1 = Money.yen(20)
        money_yen2 = Money.yen(5)

        expected = Money.yen(15)
        money_diff = money_yen1 - money_yen2
        self.assertTrue(expected == money_diff)
开发者ID:Phantom-Bridage,项目名称:lovely-hotel,代码行数:7,代码来源:test_money.py


示例3: test_return_the_sum_of_two_same_nationality_money

    def test_return_the_sum_of_two_same_nationality_money(self):
        money_yen1 = Money.yen(10)
        money_yen2 = Money.yen(5)

        expected = Money.yen(15)
        money_sum = money_yen1 + money_yen2
        self.assertTrue(expected == money_sum)
开发者ID:Phantom-Bridage,项目名称:lovely-hotel,代码行数:7,代码来源:test_money.py


示例4: test_less_equal_with_two_different_nationality_money

    def test_less_equal_with_two_different_nationality_money(self):
        greatest = Money.dollar(20.1)
        median = Money.yen(10)
        median.set_exchanger(DummyExchanger())
        least = Money.dollar(19.9)

        self.check_less_operator_of_rich_comparison(median.__le__, greatest, median, least, True)
开发者ID:Phantom-Bridage,项目名称:lovely-hotel,代码行数:7,代码来源:test_money.py


示例5: load_from_db

    def load_from_db(self, id):
        rows = self.select_by_id('player', id)
        for row in rows:
            self.id = row[0]
            self.name = row[1]
            self.password = row[2]
            self.email = row[3]

            with self.connection:
                cursor = self.connection.cursor()
                cursor.execute(
                    "select achievement_id from achievement_player where player_id={}".format(id))

                for achievement_player_row in cursor.fetchall():
                    achievement_id = achievement_player_row[0]
                    achievement = Achievement(self.connection)
                    self.achievements.append(achievement.load_from_db(achievement_id))

                cursor.execute(
                    "select counter_id from counter_player where player_id={}".format(id))

                for counter_player_row in cursor.fetchall():
                    counter_id = counter_player_row[0]
                    counter = Counter(self.connection)
                    self.counters.append(counter.load_from_db(counter_id))

                cursor.execute("select id from money where player_id={}".format(id))
                for money_row in cursor.fetchall():
                    money_id = money_row[0]
                    money = Money(self.connection)
                    money.load_from_db(money_id)
                    self.wallet[money.type] = money
开发者ID:oxanastarazhok,项目名称:Hometask,代码行数:32,代码来源:player.py


示例6: test_return_the_difference_between_the_different_nationality_money

    def test_return_the_difference_between_the_different_nationality_money(self):
        money_yen = Money.yen(10)
        money_yen.set_exchanger(DummyExchanger())
        money_dollar = Money.dollar(2)

        expected = Money.yen(9)
        money_diff = money_yen - money_dollar
        self.assertTrue(expected == money_diff)
开发者ID:Phantom-Bridage,项目名称:lovely-hotel,代码行数:8,代码来源:test_money.py


示例7: test_return_the_sum_of_two_different_nationality_money

    def test_return_the_sum_of_two_different_nationality_money(self):
        money_yen = Money.yen(10)
        money_yen.set_exchanger(DummyExchanger())
        money_dollar = Money.dollar(5)

        expected = Money.yen(12.5)
        money_sum = money_yen + money_dollar
        self.assertTrue(expected == money_sum)
开发者ID:Phantom-Bridage,项目名称:lovely-hotel,代码行数:8,代码来源:test_money.py


示例8: test_return_the_money_that_aligned_the_unit_to_currency_of_each_nationality

    def test_return_the_money_that_aligned_the_unit_to_currency_of_each_nationality(self):
        money_yen = Money.yen(10.2)
        expected = (10, 0)
        self.assertTrue(expected == money_yen.currency())

        money_dollar = Money.dollar(10.2)
        expected = (10, 20)
        self.assertTrue(expected == money_dollar.currency())
开发者ID:Phantom-Bridage,项目名称:lovely-hotel,代码行数:8,代码来源:test_money.py


示例9: test_money_exchange_yen_to_dollar

    def test_money_exchange_yen_to_dollar(self):
        money = Money.yen(10)
        money.set_exchanger(DummyExchanger())

        expected = Money.dollar(20)
        result_money = money.exchange("dollar")

        self.assertTrue(expected == result_money)
开发者ID:Phantom-Bridage,项目名称:lovely-hotel,代码行数:8,代码来源:test_money.py


示例10: testSumTimes

	def testSumTimes(self):
		fiveBucks = Money.dollar(5)
		tenFrancs = Money.franc(10)
		bank = Bank()
		bank.addRate('CHF', 'USD', 2)
		sum = Sum(fiveBucks, tenFrancs).times(2)
		result = bank.reduce(sum, 'USD')
		self.assertEquals(Money.dollar(20), result)
开发者ID:lenin,项目名称:TDDbyExample,代码行数:8,代码来源:tests.py


示例11: testMoney

 def testMoney(self):
     """"""
     USD100 = Money(100, "USD")
     EUR100 = Money(100, "EUR")
     self.assertEquals(Decimal(139),EUR100.convert_to_default())
     self.assertEquals(Decimal(100),EUR100.convert_to_default() - 39)
     Currency.objects.set_currency('1.5', 'EUR')
     exc2 = Currency.objects.get_currency("EUR")
     self.assertEquals(Decimal('1.5'), exc2.exchange_rate)
     EUR1000 = Money(1000, "EUR")
     self.assertEquals(Decimal(1500),EUR1000.convert_to_default())
     self.assertNotEquals(Decimal(150),EUR100.convert_to_default())
开发者ID:grengojbo,项目名称:django-currency,代码行数:12,代码来源:tests.py


示例12: __init__

    def __init__(self, amount=Decimal("0.0"), currency=None):
        if isinstance(amount, OriginalMoney):
            try:
                amount = amount.amount
            except AttributeError: # just in case python-money is not installed (Decimal assumes as OriginalMoney)
                pass
        currency = currency or settings.DEFAULT_CURRENCY

        if OriginalMoney == Decimal:
            OriginalMoney.__init__(self, amount)
            self.amount = amount
            self.currency = currency
        else:
            OriginalMoney.__init__(self, str(amount).replace(get_format('THOUSAND_SEPARATOR'),''), currency)
开发者ID:avelino,项目名称:votacao_paredao_bbb,代码行数:14,代码来源:datatypes.py


示例13: convert

    def convert(self, value, currency):

        currency = str(currency).upper()
        if currency != "USD":
            if currency not in self.currencies:
                print("Currency: " + str(currency))
            assert currency in self.currencies, "ERROR: currency is not in listed currencies."

            value = float(value) / 100.0
            val_money = Money(value, currency)

            return float(val_money.to("USD"))

        # Does this only for USD
        return float(value) / 100.0
开发者ID:swapit,项目名称:recommender,代码行数:15,代码来源:currency.py


示例14: test_price_attribute

    def test_price_attribute(self):
        e = SimpleMoneyModel()
        e.price = Money(3, "BGN")
        self.assertEqual(e.price, Money(3, "BGN"))

        e.price = Money.from_string("BGN 5.0")
        self.assertEqual(e.price, Money(5, "BGN"))
开发者ID:Bookitbee,项目名称:python-money,代码行数:7,代码来源:test_django.py


示例15: to_python

 def to_python(self, value):
     if value is None:
         return value
     if isinstance(value, Money):
         return value
     elif isinstance(value, Decimal):
         return Money(value)
     else:
         m = self.postgres_money_re.match(value)
         if m is not None:
             return Money(amount=m.group(1), currency=m.group(2))
         else:
             return Money.from_string(value)
开发者ID:nikicat,项目名称:python-money,代码行数:13,代码来源:fields.py


示例16: load_from_db

 def load_from_db(self, email):
     cur = con.cursor()
     sql_data_email = {
         "email": email
     }
     sql_query = """SELECT id, type, name, email, password, created, updated FROM player WHERE email=%(email)s"""
     cur.execute(sql_query, sql_data_email)
     row = cur.fetchone()
     self.player_id = row[0]
     self.name = row[2]
     self.email = row[3]
     self.password = row[4]
     self.created = row[5]
     self.updated = row[6]
     if row[1] == 'Player':
         self.__class__ = Player
     elif row[1] == 'Admin':
         self.__class__ = Admin
     else:
         self.__class__ = Moder
     self.sessions = Session().load_from_db_player(self.player_id)
     self.wallet = Money().load_from_db_player(self.player_id)
     self.achievements = Achievement().load_from_db_player(self.player_id)
     self.counter = Counter().load_from_db_player(self.player_id)
开发者ID:RubashkoM,项目名称:homework,代码行数:24,代码来源:player.py


示例17: testMultiplication

	def testMultiplication(self):
		five = Money.dollar(5)
		self.assertEquals(Money.dollar(10), five.times(2))
		self.assertEquals(Money.dollar(15), five.times(3))
开发者ID:lenin,项目名称:TDDbyExample,代码行数:4,代码来源:tests.py


示例18: convert_to_default

 def convert_to_default(self):
     return Money(OriginalMoney.convert_to_default(self))
开发者ID:avelino,项目名称:votacao_paredao_bbb,代码行数:2,代码来源:datatypes.py


示例19: __div__

 def __div__(self, other):
     return Money(OriginalMoney.__div__(self, other))
开发者ID:avelino,项目名称:votacao_paredao_bbb,代码行数:2,代码来源:datatypes.py


示例20: testPlusReturnsSum

	def testPlusReturnsSum(self):
		five = Money.dollar(5)
		sum = five.plus(five)
		self.assertEquals(five, sum.augend)
		self.assertEquals(five, sum.addend)
开发者ID:lenin,项目名称:TDDbyExample,代码行数:5,代码来源:tests.py



注:本文中的money.Money类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python localization.format_money函数代码示例发布时间:2022-05-27
下一篇:
Python models.Repository类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap