我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用django.template.defaultfilters.floatformat()。
def intword(value): """ Converts a large integer to a friendly text representation. Works best for numbers over 1 million. For example, 1000000 becomes '1.0 million', 1200000 becomes '1.2 million' and '1200000000' becomes '1.2 billion'. """ try: value = int(value) except (TypeError, ValueError): return value if value < 1000000: return value def _check_for_i18n(value, float_formatted, string_formatted): """ Use the i18n enabled defaultfilters.floatformat if possible """ if settings.USE_L10N: value = defaultfilters.floatformat(value, 1) template = string_formatted else: template = float_formatted return template % {'value': value} for exponent, converters in intword_converters: large_number = 10 ** exponent if value < large_number * 1000: new_value = value / float(large_number) return _check_for_i18n(new_value, *converters(new_value)) return value
def get_description_deals(user, obj): order_id = obj.pk if not user == obj.user: if obj.el.sale.user == user: order_id = obj.el.sale.pk if obj.el.buy.user == user: order_id = obj.el.buy.pk if obj.w_action(user) == 'sale': return u"??????? {w_amo_sum_total} {left} ? ?????? ?????? #{pk} ?? ???? {rate} {right} ????? {w_total_total} {right} (-{commission}%)".format(**{ "w_amo_sum_total": floatformat(obj.el._part_amo_sum, -8), "left": obj.el.pair.left, "pk": order_id, "rate": floatformat(obj.profitable.rate, -8), "right": obj.el.pair.right, "w_total_total": floatformat(obj.el._part_amo_sum * obj.el._rate, -8), #"w_total_total": floatformat(obj.el._part_amo_sum * obj.el._rate * (1 - obj.commission / D(100)), -8), "commission": obj.commission, }) if obj.w_action(user) == 'buy': return u"??????? {w_amo_sum_total} {left} (-{commission}%) ? ?????? ?????? #{pk} ?? ???? {rate} {right}".format(**{ "w_amo_sum_total": floatformat(obj.el._part_amo_sum, -8), #"w_amo_sum_total": floatformat(obj.el._part_amo_sum * (1 - obj.commission / D(100)), -8), "left": obj.el.pair.left, "pk": order_id, "rate": floatformat(obj.profitable.rate, -8), "right": obj.el.pair.right, "commission": obj.commission, })
def get_total_deals(user, obj): order_id = obj.pk if not user == obj.user: if obj.el.sale.user == user: order_id = obj.el.sale.pk if obj.el.buy.user == user: order_id = obj.el.buy.pk if obj.w_action(user) == 'sale': return u"+{w_total_total} {right}".format(**{ "w_amo_sum_total": floatformat(obj.el._part_amo_sum, -8), "left": obj.el.pair.left, "pk": order_id, "rate": floatformat(obj.profitable.rate, -8), "right": obj.el.pair.right, "w_total_total": floatformat(obj.el._part_amo_sum * obj.el._rate * (1 - obj.commission / D(100)), -8), "commission": obj.commission, }) if obj.w_action(user) == 'buy': return u"+{w_total_total} {left}".format(**{ "w_amo_sum_total": floatformat(obj.el._part_amo_sum * (1 - obj.commission / D(100)), -8), "left": obj.el.pair.left, "pk": order_id, "rate": floatformat(obj.profitable.rate, -8), "right": obj.el.pair.right, "w_total_total": floatformat(obj.el._part_amo_sum * (1 - obj.commission / D(100)), -8), "commission": obj.commission, })
def get_commission(obj): flr={} if obj.get('valuta_id'): flr.update({"valuta":obj.get('valuta_id')}) if obj.get('paymethod_id'): flr.update({"paymethod":obj.get('paymethod_id')}) if obj.get('action'): flr.update({"action":obj.get('action')}) return floatformat(ProfileBalance.sum_commission(flr), -8)
def commiss(self): return floatformat(normalized(self._commission_debit), -8)
def sum_order_current(self): if self.is_action('sale'): res = self.sale._sum_ret if self.is_action('buy'): res = self.buy._ret_amount return floatformat(res, -8)
def order(request, form): dajax = Dajax() q=deserialize_form(form) ttype = '' if not q.get('buy-amount', None) is None: ttype = 'buy' if not q.get('sale-amount', None) is None: ttype = 'sale' form = OrdersForm(prefix=ttype, data=q) if form.is_valid(): c=form.cleaned_data user=request.user if user.is_authenticated() and user.is_active: pair, amount, rate = c.get('pair'), c.get('amount'), c.get('rate') total, commission, pos = pair.calc(amount, rate, ttype) if ttype == 'buy': pos = pair.right if ttype == 'sale': pos = pair.left valuta = pos.value balance = user.orders_balance(valuta) if ttype == 'buy': _sum = balance - total if ttype == 'sale': _sum = balance - amount if _sum >= 0: _ret = getattr(pair, "order_%s" % ttype)(user, amount, rate) dajax.remove_css_class('#{type}_form input'.format(**{"type":ttype}), 'error') dajax.script("location.reload();") else: text = "????? ?????? ????????? ??? ?????? ?? {sum} {valuta}".format(**{"sum":floatformat(-_sum, -8), "valuta": pos }) dajax.script("$('#info_{type}').text('{text}');".format(**{"type":ttype, "text":text, })) else: pair, amount, rate = c.get('pair'), c.get('amount'), c.get('rate') total, commission, pos = pair.calc(amount, rate, ttype) if ttype == 'buy': _sum = total if ttype == 'sale': _sum = amount text = "????? ?????? ????????? ??? ?????? ?? {sum} {valuta}".format(**{"sum":floatformat(-_sum, -8), "valuta": pos }) dajax.script("$('#info_{type}').text('{text}');".format(**{"type":ttype, "text":text, })) else: dajax.script("$('#info_{type}').text('{text}');".format(**{"type":ttype, "text":"??????????? ????????? ???? ?? ?????.", })) for error in form.errors: dajax.add_css_class('#id_%s-%s' % (ttype, error), 'error') return dajax.json()
def calc_paymethod(request, value, paymethod, act="-"): dajax = Dajax() v = get_object_or_404(PaymentMethod, pk=paymethod, disable=False) calc_value = v.calc_commission(D(value)) calc_value1 = v.calc_commission(D(value), True) if act == "-": dajax.assign('#calc-value-result', 'value', floatformat(calc_value, -8).replace(",", ".")) else: dajax.assign('#balance-value', 'value', floatformat(calc_value1, -8).replace(",", ".")) dajax.assign('#calc-value-result', 'value', floatformat(value, -8).replace(",", ".")) return dajax.json()
def w_min_commission(self): return u"???. {amount} {valuta}".format(**{ "amount":floatformat(self.min_commission, -8), "valuta":self.valuta })
def w_max_commission(self): return u"????. {amount} {valuta}".format(**{ "amount":floatformat(self.max_commission, -8), "valuta":self.valuta })
def w_commission(self): if self.commission > _Zero: return u"{commission}% ".format(**{"commission": floatformat(self.commission, -2)}) return ""
def commission_records_orders(self): for v in Valuta.objects.all(): yield v, floatformat(Orders.sum_from_commission(v.value), -8), v.pk
def commission_records(self): for v in Valuta.objects.all(): yield v, floatformat(self._commission_records(v.value), -8), v.pk
def balance_left(self): return mark_safe("<span>{amo}<span> {pos}".format(**{"amo":floatformat(self.amount_left, -8), "pos":self.pair.left}))
def balance_right(self): return mark_safe("<span>{amo}</span> {pos}".format(**{"amo":floatformat(self.amount_right, -8), "pos":self.pair.right}))
def w_total_transaction(self): return "%s%s %s" % (self.action, floatformat(self._total_transaction, -8), self.valuta)
def w_commission(self): if self.min_commission > _Zero and (self.value * self.commission / D(100)) < self.min_commission: return u"{commission} {valuta}".format(**{"commission":floatformat(self.min_commission, -8), "valuta": self.valuta}) elif self.max_commission > _Zero and (self.value * self.commission / D(100)) > self.max_commission: return u"{commission} {valuta}".format(**{"commission":floatformat(self.max_commission, -8), "valuta": self.valuta}) else: return u"{commission}%".format(**{"commission":self.commission,})
def total_admin(self): v = normalized(self.value - self._commission_debit, where="DOWN") return floatformat(v, -8)
def get_percentage(self, obj): return floatformat(obj['share']*100, -2)
def get_display_share(self, obj): return floatformat(obj['share']*100)
def display_fee(self, amount=None): if amount is None: amount = self.pay if not amount: return '' if self.currency in CURRENCY_SYMBOLS: return '{}{}'.format(CURRENCY_SYMBOLS[self.currency], floatformat(amount, arg=-2)) return amount or ''
def display_fee(self, amount=None): if amount is None: amount = self.fee if self.currency in CURRENCY_SYMBOLS: return '{}{}'.format(CURRENCY_SYMBOLS[self.currency], floatformat(amount, arg=-2)) return amount or ''
def handle(self, *args, **options): """ Update periodic update events and send notifications for upcoming update events. """ # command to run: python manage.py tunga_export_payments participant_payments = ParticipantPayment.objects.filter(participant__task__paid=True) print('participant_payments', len(participant_payments)) with open('developer_payments.csv', 'wb') as csvfile: spamwriter = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) spamwriter.writerow([ 'Task', 'Fee', 'Developer', 'Dev BTC Address', 'BTC Sent', 'Task BTC Address', 'Invoice Date', 'Paid By', 'URL', 'Developer Invoice', 'Client Invoice' ]) for payment in participant_payments: row = [ payment.participant.task.summary, 'EUR {}'.format(floatformat(payment.participant.task.fee, -2)), payment.participant.user.display_name, payment.destination, 'BTC {}'.format(floatformat(payment.btc_sent, -6)), payment.participant.task.btc_address, payment.participant.task.taskinvoice_set.first().created_at.strftime("%d %b, %Y"), payment.participant.task.user.display_name, '{}/work/{}'.format(TUNGA_URL, payment.participant.task.id), '{}/api/task/{}/download/invoice/?format=pdf&type=developer'.format(TUNGA_URL, payment.participant.task.id), '{}/api/task/{}/download/invoice/?format=pdf&type=client'.format(TUNGA_URL, payment.participant.task.id) ] spamwriter.writerow(row)