当前位置: 首页>>代码示例>>Python>>正文


Python money.Money类代码示例

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


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


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