@@ -401,12 +401,18 @@ def format_decimal(
401
401
u'1.235'
402
402
>>> format_decimal(1.2346, locale='en_US', decimal_quantization=False)
403
403
u'1.2346'
404
+ >>> format_decimal(12345.67, locale='fr_CA', group_separator=False)
405
+ u'12345,67'
406
+ >>> format_decimal(12345.67, locale='en_US', group_separator=True)
407
+ u'12,345.67'
404
408
405
409
:param number: the number to format
406
410
:param format:
407
411
:param locale: the `Locale` object or locale identifier
408
412
:param decimal_quantization: Truncate and round high-precision numbers to
409
413
the format pattern. Defaults to `True`.
414
+ :param group_separator: Boolean to switch group separator on/off in a locale's
415
+ number format.
410
416
"""
411
417
locale = Locale .parse (locale )
412
418
if not format :
@@ -472,6 +478,12 @@ def format_currency(
472
478
...
473
479
UnknownCurrencyFormatError: "'unknown' is not a known currency format type"
474
480
481
+ >>> format_currency(101299.98, 'EUR', locale='en_US', group_separator=False)
482
+ u'\u20ac 101299.98'
483
+
484
+ >>> format_currency(101299.98, 'EUR', locale='en_US', group_separator=True)
485
+ u'€101,299.98'
486
+
475
487
You can also pass format_type='name' to use long display names. The order of
476
488
the number and currency name, along with the correct localized plural form
477
489
of the currency name, is chosen according to locale:
@@ -500,6 +512,8 @@ def format_currency(
500
512
:param format_type: the currency format type to use
501
513
:param decimal_quantization: Truncate and round high-precision numbers to
502
514
the format pattern. Defaults to `True`.
515
+ :param group_separator: Boolean to switch group separator on/off in a locale's
516
+ number format.
503
517
504
518
"""
505
519
if format_type == 'name' :
@@ -582,11 +596,19 @@ def format_percent(
582
596
>>> format_percent(23.9876, locale='en_US', decimal_quantization=False)
583
597
u'2,398.76%'
584
598
599
+ >>> format_percent(229291.1234, locale='pt_BR', group_separator=False)
600
+ u'22929112%'
601
+
602
+ >>> format_percent(229291.1234, locale='pt_BR', group_separator=True)
603
+ u'22.929.112%'
604
+
585
605
:param number: the percent number to format
586
606
:param format:
587
607
:param locale: the `Locale` object or locale identifier
588
608
:param decimal_quantization: Truncate and round high-precision numbers to
589
609
the format pattern. Defaults to `True`.
610
+ :param group_separator: Boolean to switch group separator on/off in a locale's
611
+ number format.
590
612
"""
591
613
locale = Locale .parse (locale )
592
614
if not format :
@@ -597,7 +619,7 @@ def format_percent(
597
619
598
620
599
621
def format_scientific (
600
- number , format = None , locale = LC_NUMERIC , decimal_quantization = True , group_separator = True ):
622
+ number , format = None , locale = LC_NUMERIC , decimal_quantization = True ):
601
623
"""Return value formatted in scientific notation for a specific locale.
602
624
603
625
>>> format_scientific(10000, locale='en_US')
@@ -628,7 +650,7 @@ def format_scientific(
628
650
format = locale .scientific_formats .get (format )
629
651
pattern = parse_pattern (format )
630
652
return pattern .apply (
631
- number , locale , decimal_quantization = decimal_quantization , group_separator = group_separator )
653
+ number , locale , decimal_quantization = decimal_quantization )
632
654
633
655
634
656
class NumberFormatError (ValueError ):
0 commit comments