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


Python locale.currency方法代码示例

本文整理汇总了Python中locale.currency方法的典型用法代码示例。如果您正苦于以下问题:Python locale.currency方法的具体用法?Python locale.currency怎么用?Python locale.currency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在locale的用法示例。


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

示例1: download_financial

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def download_financial(request, post_slug):
    posting = get_object_or_404(TAPosting, slug=post_slug, unit__in=request.units)
    all_offerings = CourseOffering.objects.filter(semester=posting.semester, owner=posting.unit)
    # ignore excluded courses
    excl = set(posting.excluded())
    offerings = [o for o in all_offerings if o.course_id not in excl and posting.ta_count(o) > 0]
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'inline; filename="%s-financials-%s.csv"' % \
                                      (post_slug, datetime.datetime.now().strftime('%Y%m%d'))
    writer = csv.writer(response)
    writer.writerow(['Offering', 'Instructor(s)', 'Enrollment', 'Campus', 'Number of TAs', 'Assigned BU',
                     'Total Amount'])
    for o in offerings:
        writer.writerow([o.name(), o.instructors_str(), '(%s/%s)' % (o.enrl_tot, o.enrl_cap), o.get_campus_display(),
                         posting.ta_count(o), posting.assigned_bu(o), locale.currency(float(posting.total_pay(o)))])
    return response 
开发者ID:sfu-fas,项目名称:coursys,代码行数:18,代码来源:views.py

示例2: get_price

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def get_price(coin, curr=None):
    '''Get the data on coins'''
    curr = curr or CONFIG['api'].get('currency', 'USD')
    fmt = 'https://min-api.cryptocompare.com/data/pricemultifull?fsyms={}&tsyms={}'

    try:
        r = requests.get(fmt.format(coin, curr))
    except requests.exceptions.RequestException:
        sys.exit('Could not complete request')

    try:
        data_raw = r.json()['RAW']
        return [(float(data_raw[c][curr]['PRICE']),
                 float(data_raw[c][curr]['HIGH24HOUR']),
                 float(data_raw[c][curr]['LOW24HOUR'])) for c in coin.split(',') if c in data_raw.keys()]
    except:
        sys.exit('Could not parse data') 
开发者ID:huwwp,项目名称:cryptop,代码行数:19,代码来源:cryptop.py

示例3: update_labels

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def update_labels(self):

        # update all labels via tk StringVar()
        self.last_price_value.set(str(self.get_last_price()))
        self.current_position_pnl.set(str(self.get_position_pnl()) + '%')
        self.account_value_pnl.set(str(round(percent_change(get_account_value(), float(config.initial_amount)), 2)) + '%')
        self.current_position_value.set(str(get_position()['quantity']) + " @ " + str(get_position()['entry']))
        self.account_value_text.set(locale.currency(get_account_value(), grouping=True))
        self.ticker_value.set(self.get_ticker())

        # Update trade history box
        self.trade_history_list.delete(0, 'end')
        for trade in read_all():
            self.trade_history_list.insert(0, trade)

    # get last price via xpath 
开发者ID:Robswc,项目名称:tradingview-trainer,代码行数:18,代码来源:app.py

示例4: money

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def money(value):
    locale.setlocale(locale.LC_ALL, '')
    try:
        if not value:
            return locale.currency(0.0)
        return locale.currency(value, symbol=True, grouping=True)
    except ValueError:
        locale.setlocale(locale.LC_MONETARY, 'en_US.utf8')
        if not value:
            return locale.currency(0.0)
        return locale.currency(value, symbol=True, grouping=True) 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:13,代码来源:donation_tags.py

示例5: currency

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def currency(i):
    try:
        return locale.currency(decimal.Decimal(i), grouping=True)
    except decimal.InvalidOperation:
        return locale.currency(0) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:7,代码来源:currency.py

示例6: view_financial_summary

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def view_financial_summary(request, unit_slug, semester,):
    hiring_semester = get_object_or_404(HiringSemester,
                                        semester__name=semester,
                                        unit__in=request.units,
                                        unit__label=unit_slug)
    contracts = TAContract.objects.signed(hiring_semester)
    pay = 0
    bus = 0
    tacourses = TACourse.objects.filter(contract__in=contracts)
    course_offerings = set()
    for course in tacourses:
        pay += course.total
        bus += course.total_bu
        course_offerings.add(course.course)
    pay = locale.currency(float(pay))
    pay = '%s' % (pay)
    offerings = []
    tac = 0
    for o in course_offerings:
        courses = tacourses.filter(course=o)
        total_pay = 0
        total_bus = decimal.Decimal(0)
        for c in courses:
            total_pay += c.total
            total_bus += c.total_bu

        total_pay = '%s' % (locale.currency(float(total_pay)))
        total_bus = "%.2f" % total_bus
        tas = courses.count()
        o.total_pay = total_pay
        o.total_bus = total_bus
        o.tas = tas
        tac += tas
        offerings.append(o)
    info = {'course_total': len(offerings), 'bu_total': bus, 'pay_total': pay, 'ta_count': tac}
    context = {'hiring_semester': hiring_semester, 'info': info, 'offerings': offerings, 'unit_slug': unit_slug,
               'semester': semester}
    return render(request, 'tacontracts/view_financial.html', context) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:40,代码来源:views.py

示例7: download_financials

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def download_financials(request, unit_slug, semester,):
    hiring_semester = get_object_or_404(HiringSemester,
                                        semester__name=semester,
                                        unit__in=request.units,
                                        unit__label=unit_slug)
    contracts = TAContract.objects.signed(hiring_semester)
    tacourses = TACourse.objects.filter(contract__in=contracts)
    course_offerings = set()
    for course in tacourses:
        course_offerings.add(course.course)
    offerings = []
    for o in course_offerings:
        courses = tacourses.filter(course=o)
        total_pay = 0
        total_bus = decimal.Decimal(0)
        for c in courses:
            total_pay += c.total
            total_bus += c.total_bu
        total_pay = '%s' % (locale.currency(float(total_pay)))
        total_bus = "%.2f" % total_bus
        tas = courses.count()
        o.total_pay = total_pay
        o.total_bus = total_bus
        o.tas = tas
        offerings.append(o)
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'inline; filename="%s-%s-financials-%s.csv"' % \
                                      (unit_slug, semester, datetime.datetime.now().strftime('%Y%m%d'))
    writer = csv.writer(response)
    writer.writerow(['Offering', 'Instructor(s)', 'Enrollment', 'Campus', 'Number of TAs', 'Assigned BU',
                     'Total Amount'])
    for o in offerings:
        writer.writerow([o.name(), o.instructors_str(), '(%s/%s)' % (o.enrl_tot, o.enrl_cap), o.get_campus_display(),
                         o.tas, o.total_bus, o.total_pay])
    return response 
开发者ID:sfu-fas,项目名称:coursys,代码行数:37,代码来源:views.py

示例8: _format_currency

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def _format_currency(i):
    """used to properly format money"""
    return locale.currency(float(i), grouping=True) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:5,代码来源:views.py

示例9: display_all_total_pay

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def display_all_total_pay(val):
    amt = locale.currency(float(val))
    return '%s' % (amt) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:5,代码来源:ta_display.py

示例10: dollar

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def dollar(value):
    """Formats the float value into two-decimal-points dollar amount.
    From http://flask.pocoo.org/docs/templating/

    Positional arguments:
    value -- the string representation of a float to perform the operation on.

    Returns:
    Dollar formatted string.
    """
    return locale.currency(float(value), grouping=True) 
开发者ID:Robpol86,项目名称:Flask-Large-Application-Example,代码行数:13,代码来源:middleware.py

示例11: _test_currency

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def _test_currency(self, value, out, **format_opts):
        self.assertEqual(locale.currency(value, **format_opts), out) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_locale.py

示例12: str_formatter

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def str_formatter(coin, val, held):
    '''Prepare the coin strings as per ini length/decimal place values'''
    max_length = CONFIG['theme'].getint('field_length', 13)
    dec_place = CONFIG['theme'].getint('dec_places', 2)
    avg_length = CONFIG['theme'].getint('dec_places', 2) + 10
    held_str = '{:>{},.8f}'.format(float(held), max_length)
    val_str = '{:>{},.{}f}'.format(float(held) * val[0], max_length, dec_place)
    return '  {:<5} {:>{}}  {} {:>{}} {:>{}} {:>{}}'.format(coin,
        locale.currency(val[0], grouping=True)[:max_length], avg_length,
        held_str[:max_length],
        locale.currency(float(held) * val[0], grouping=True)[:max_length], avg_length,
        locale.currency(val[1], grouping=True)[:max_length], avg_length,
        locale.currency(val[2], grouping=True)[:max_length], avg_length) 
开发者ID:huwwp,项目名称:cryptop,代码行数:15,代码来源:cryptop.py

示例13: write_scr

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def write_scr(stdscr, wallet, y, x):
    '''Write text and formatting to screen'''
    first_pad = '{:>{}}'.format('', CONFIG['theme'].getint('dec_places', 2) + 10 - 3)
    second_pad = ' ' * (CONFIG['theme'].getint('field_length', 13) - 2)
    third_pad =  ' ' * (CONFIG['theme'].getint('field_length', 13) - 3)

    if y >= 1:
        stdscr.addnstr(0, 0, 'cryptop v0.2.0', x, curses.color_pair(2))
    if y >= 2:
        header = '  COIN{}PRICE{}HELD {}VAL{}HIGH {}LOW  '.format(first_pad, second_pad, third_pad, first_pad, first_pad)
        stdscr.addnstr(1, 0, header, x, curses.color_pair(3))

    total = 0
    coinl = list(wallet.keys())
    heldl = list(wallet.values())
    if coinl:
        coinvl = get_price(','.join(coinl))

        if y > 3:
            s = sorted(list(zip(coinl, coinvl, heldl)), key=SORT_FNS[SORTS[COLUMN]], reverse=ORDER)
            coinl = list(x[0] for x in s)
            coinvl = list(x[1] for x in s)
            heldl = list(x[2] for x in s)
            for coin, val, held in zip(coinl, coinvl, heldl):
                if coinl.index(coin) + 2 < y:
                    stdscr.addnstr(coinl.index(coin) + 2, 0,
                    str_formatter(coin, val, held), x, curses.color_pair(2))
                total += float(held) * val[0]

    if y > len(coinl) + 3:
        stdscr.addnstr(y - 2, 0, 'Total Holdings: {:10}    '
            .format(locale.currency(total, grouping=True)), x, curses.color_pair(3))
        stdscr.addnstr(y - 1, 0,
            '[A] Add/update coin [R] Remove coin [S] Sort [C] Cycle sort [0\Q]Exit', x,
            curses.color_pair(2)) 
开发者ID:huwwp,项目名称:cryptop,代码行数:37,代码来源:cryptop.py

示例14: test_currency_us

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def test_currency_us():
    assert locale.currency(10.5) == "$10.50" 
开发者ID:PacktPublishing,项目名称:pytest-Quick-Start-Guide,代码行数:4,代码来源:test_marks.py

示例15: test_currency_br

# 需要导入模块: import locale [as 别名]
# 或者: from locale import currency [as 别名]
def test_currency_br():
    assert locale.currency(10.5) == "R$ 10,50" 
开发者ID:PacktPublishing,项目名称:pytest-Quick-Start-Guide,代码行数:4,代码来源:test_marks.py


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