speech_asr
2023-03-10 9e2a04d0e0823c0fe2f3dc9fafa68d2045b773d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
 
from __future__ import division
 
from decimal import ROUND_HALF_UP, Decimal
 
 
def parse_currency_parts(value, is_int_with_cents=True):
    if isinstance(value, int):
        if is_int_with_cents:
            # assume cents if value is integer
            negative = value < 0
            value = abs(value)
            integer, cents = divmod(value, 100)
        else:
            negative = value < 0
            integer, cents = abs(value), 0
 
    else:
        value = Decimal(value)
        value = value.quantize(
            Decimal('.01'),
            rounding=ROUND_HALF_UP
        )
        negative = value < 0
        value = abs(value)
        integer, fraction = divmod(value, 1)
        integer = int(integer)
        cents = int(fraction * 100)
 
    return integer, cents, negative
 
 
def prefix_currency(prefix, base):
    return tuple("%s %s" % (prefix, i) for i in base)