<commit_before>from decimal import Decimal, ROUND_UP
from currencies.models import Currency


def calculate_price(price, currency):
    price = Decimal(price)
    currency = Currency.objects.get(code__exact=currency)
    default = Currency.objects.get(is_default=True)

    # First, convert from the default currency to the base currency
    price = price / default.factor

    # Now, convert from the base to the given currency
    price = price * currency.factor

    return price.quantize(Decimal("0.01"), rounding=ROUND_UP)
<commit_msg>Add convert multicurrency function<commit_after>from decimal import Decimal, ROUND_UP
from currencies.models import Currency


def calculate_price(price, currency):
    price = Decimal(price)
    currency = Currency.objects.get(code__exact=currency)
    default = Currency.objects.get(is_default=True)

    # First, convert from the default currency to the base currency
    price = price / default.factor

    # Now, convert from the base to the given currency
    price = price * currency.factor

    return price.quantize(Decimal("0.01"), rounding=ROUND_UP)

    
def convert(amount, from_, to):
    amount = Decimal(amount)
    from_currency = Currency.objects.get(code__exact=from_)
    to_currency = Currency.objects.get(code__exact=to)
    amount = amount * (to_currency.factor / from_currency.factor)  
    
    return amount.quantize(Decimal("0.01"), rounding=ROUND_UP)
{'fraction_non_alphanumeric': 0.08815232722143865, 'fraction_numerical': 0.006346967559943582, 'mean_word_length': 4.216911764705882, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4183613', 'n_tokens_mistral': 425, 'n_tokens_neox': 400, 'n_words': 112}