當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。