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

Python numbers.format_currency函数代码示例

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

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



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

示例1: money_format

def money_format(req, amount, code=None, prefix=None, suffix=None,
                 currency=None):
    if amount is None:
        return ''

    cfg = req.registry.settings
    loc = req.current_locale

    if currency is not None:
        code = currency.code
        prefix = currency.prefix
        suffix = currency.suffix

    if code is None:
        code = cfg.get('netprofile.currency.default')

    if code is None:
        formatted = format_decimal(amount, locale=loc)
    elif code in loc.currencies:
        formatted = format_currency(amount, code, locale=loc)
    else:
        stdloc = req.locales[cfg.get('pyramid.default_locale_name', 'en')]
        if code in stdloc.currencies:
            formatted = format_currency(amount, code, locale=stdloc)
        else:
            formatted = format_decimal(amount, locale=loc)

    ret = []
    if prefix:
        ret.append(prefix)
    ret.append(formatted)
    if suffix:
        ret.append(suffix)
    return '\xa0'.join(ret)
开发者ID:unikmhz,项目名称:npui,代码行数:34,代码来源:locale.py


示例2: money_format_long

def money_format_long(req, amount, code=None, currency=None):
    if amount is None:
        return ''

    cfg = req.registry.settings
    loc = req.current_locale

    if currency is not None:
        code = currency.code

    if code is None:
        code = cfg.get('netprofile.currency.default')

    if code is not None:
        if code in loc.currencies:
            return format_currency(amount, code, locale=loc,
                                   format='0.######## ¤¤¤',
                                   currency_digits=False)
        else:
            stdloc = req.locales[cfg.get('pyramid.default_locale_name', 'en')]
            if code in stdloc.currencies:
                return format_currency(amount, code, locale=stdloc,
                                       format='0.######## ¤¤¤',
                                       currency_digits=False)

    return format_decimal(amount, locale=loc, format='0.########')
开发者ID:unikmhz,项目名称:npui,代码行数:26,代码来源:locale.py


示例3: moneyfy

def moneyfy(currency, amount):
    '''Format amount of money according to a locale'''
    if currency.lower() in ('€', 'eur'):
        return format_currency(int(amount), 'EUR', locale='en_GB').split('.')[0]
    elif currency.lower() in ('£', 'gbp'):
        return format_currency(int(amount), 'GBP', locale='en_GB').split('.')[0]
    return amount
开发者ID:fhoehl,项目名称:lookaroundeu2016,代码行数:7,代码来源:csv2json.py


示例4: currency_format

def currency_format(context, value, currency='EUR', decimal=2):
    if value is None:
        value = 0.0

    lang = translation.get_language()
    locale = context.get('locale', lang)

    if isinstance(value, six.string_types):
        symbol = get_currency_symbol(currency, locale=locale)
        if not symbol:
            symbol = currency
        return mark_safe('%s %s' % (value, symbol))

    value = round(value, decimal)
    formatted = format_currency(value, currency, locale=locale)
    symbol = get_currency_symbol(currency, locale=locale)
    if not context.get('filter_country') and len(symbol) == 1:
        # When we have possibly mixed currencies, show three letter symbol
        # This improves alignment
        formatted = formatted.replace(symbol, currency)
    if decimal == 0:
        zero_amount = format_currency(0, currency, locale=locale)
        zero_decimals = zero_amount.replace(symbol, '').strip()[1:]
        formatted = formatted.replace(zero_decimals, '')
    return mark_safe(formatted.replace(' ', ' '))
开发者ID:correctiv,项目名称:correctiv-eurosfueraerzte,代码行数:25,代码来源:number_utils.py


示例5: test_format_currency_long_display_name

def test_format_currency_long_display_name():
    assert (numbers.format_currency(1099.98, 'USD', locale='en_US', format_type='name')
            == u'1,099.98 US dollars')
    assert (numbers.format_currency(1.00, 'USD', locale='en_US', format_type='name')
            == u'1.00 US dollar')
    assert (numbers.format_currency(1.00, 'EUR', locale='en_US', format_type='name')
            == u'1.00 euro')
    assert (numbers.format_currency(2, 'EUR', locale='en_US', format_type='name')
            == u'2.00 euros')
    # This tests that '{1} {0}' unitPatterns are found:
    assert (numbers.format_currency(1, 'USD', locale='sw', format_type='name')
            == u'dola ya Marekani 1.00')
    # This tests unicode chars:
    assert (numbers.format_currency(1099.98, 'USD', locale='es_GT', format_type='name')
            == u'dólares estadounidenses 1,099.98')
    # Test for completely unknown currency, should fallback to currency code
    assert (numbers.format_currency(1099.98, 'XAB', locale='en_US', format_type='name')
            == u'1,099.98 XAB')

    # Test for finding different unit patterns depending on count
    assert (numbers.format_currency(1, 'USD', locale='ro', format_type='name')
            == u'1,00 dolar american')
    assert (numbers.format_currency(2, 'USD', locale='ro', format_type='name')
            == u'2,00 dolari americani')
    assert (numbers.format_currency(100, 'USD', locale='ro', format_type='name')
            == u'100,00 de dolari americani')
开发者ID:JonathanRRogers,项目名称:babel,代码行数:26,代码来源:test_numbers.py


示例6: test_format_currency_format_type

def test_format_currency_format_type():
    assert (numbers.format_currency(1099.98, 'USD', locale='en_US',
                                    format_type="standard")
            == u'$1,099.98')
    assert (numbers.format_currency(0, 'USD', locale='en_US',
                                    format_type="standard")
            == u'$0.00')

    assert (numbers.format_currency(1099.98, 'USD', locale='en_US',
                                    format_type="accounting")
            == u'$1,099.98')
    assert (numbers.format_currency(0, 'USD', locale='en_US',
                                    format_type="accounting")
            == u'$0.00')

    with pytest.raises(numbers.UnknownCurrencyFormatError) as excinfo:
        numbers.format_currency(1099.98, 'USD', locale='en_US',
                                format_type='unknown')
    assert excinfo.value.args[0] == "'unknown' is not a known currency format type"

    assert (numbers.format_currency(1099.98, 'JPY', locale='en_US')
            == u'\xa51,100')
    assert (numbers.format_currency(1099.98, 'COP', u'#,##0.00', locale='es_ES')
            == u'1.100')
    assert (numbers.format_currency(1099.98, 'JPY', locale='en_US',
                                    currency_digits=False)
            == u'\xa51,099.98')
    assert (numbers.format_currency(1099.98, 'COP', u'#,##0.00', locale='es_ES',
                                    currency_digits=False)
            == u'1.099,98')
开发者ID:JonathanRRogers,项目名称:babel,代码行数:30,代码来源:test_numbers.py


示例7: currency_string

def currency_string(value, currency):
    """Takes a value and currency code and uses babel
    to properly format the currency into a localized string"""
    if value < 0:
        return "-" + format_currency(abs(value), currency)
    else:
        return format_currency(value, currency)
开发者ID:tfree87,项目名称:pygnucash,代码行数:7,代码来源:gnucash2ledger.py


示例8: list_splits

def list_splits(trans):
    """Returns a string with a list of splits for the given transaction
    (trans)"""
    temp = ""
    for split in trans.splits:
        if split.reconcile_state == "y":
            temp +="\t* "
        elif split.reconcile_state == "c":
            temp +="\t! "
        else:
            temp += "\t"
        temp += "{:60s}\t".format(full_acc_name(split.account))
        if split.account.commodity != trans.currency and args.posting_cost == True:
            temp += "{:f} {} @@ {}".format(split.quantity,
                                           split.account.commodity,
                                           format_currency(
                                   abs(split.value), str(trans.currency)))
        elif split.account.commodity != trans.currency and args.posting_cost == False:
            temp += "{:f} {} @ {}".format(split.quantity,
                                           split.account.commodity,
                                           format_currency(
                                   abs(split.commodity_price),
                                               str(trans.currency)))
        else:
            temp += "{}".format(currency_string(split.value, str(trans.currency)))
        if split.memo:
            temp += "\t; {}".format(split.memo)
        temp += "\n"
    return temp
开发者ID:tfree87,项目名称:pygnucash,代码行数:29,代码来源:gnucash2ledger.py


示例9: make_campaign_table_row

    def make_campaign_table_row(cls, id, start, end, target, bid, impressions,
                                clicks, is_live, is_active, url, is_total):
        if impressions:
            cpm = format_currency(promote.cost_per_mille(bid, impressions),
                                  'USD', locale=c.locale)
        else:
            cpm = '---'

        if clicks:
            cpc = format_currency(promote.cost_per_click(bid, clicks), 'USD',
                                  locale=c.locale)
            ctr = format_number(_clickthrough_rate(impressions, clicks))
        else:
            cpc = '---'
            ctr = '---'

        return {
            'id': id,
            'start': start,
            'end': end,
            'target': target,
            'bid': format_currency(bid, 'USD', locale=c.locale),
            'impressions': format_number(impressions),
            'cpm': cpm,
            'clicks': format_number(clicks),
            'cpc': cpc,
            'ctr': ctr,
            'live': is_live,
            'active': is_active,
            'url': url,
            'csv': url + '.csv',
            'total': is_total,
        }
开发者ID:Chef1991,项目名称:reddit,代码行数:33,代码来源:trafficpages.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python numbers.format_decimal函数代码示例发布时间:2022-05-24
下一篇:
Python pofile.write_po函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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