Truncates money amount to the number of decimals corresponding to the currency
543456
def truncate_money(money: Money) -> Money:
    """"""
    amount = truncate_to(money.amount, money.currency)
    return Money(amount, money.currency)
914020
function decimalLength(n) {
	let ns = cleanNumber(n).toString();
	let ems = ns.match(/e([\+\-]\d+)$/);
	let e = 0;
	if (ems && ems[1]) e = parseInt(ems[1]);
	ns = ns.replace(/e[\-\+]\d+$/, '');	
	let parts = ns.split('.', 2);
	if (parts.length === 1) return -e;
	return parts[1].length - e;
}
126462
def currency(money):
    
    decimals = getattr(settings, 'MIDNIGHT_CATALOG_DECIMALS', 2)
    money = round(float(money), decimals)
    symbol = getattr(settings, 'MIDNIGHT_CATALOG_CURRENCY', 'руб')
    if decimals > 0:
        formatted = (str("%0."+str(decimals)+"f") % money)[-decimals-1:]
    else:
        formatted = ""
    return "%s%s %s" % (intcomma(int(money)), formatted, symbol)
254784
def round(self, ndigits=0):
        
        if ndigits is None:
            ndigits = 0
        return self.__class__(
            amount=self.amount.quantize(Decimal('1e' + str(-ndigits))),
            currency=self.currency)
693651
public function formatMoney($amount, $currency = '€')
    {
        $symbols = array('€', '$', '£', '¥', '₤', 'kr', '₺');

        switch ($this->locale) {

            case 'de':
            case 'tr':
            case 'pt':
                $amount = number_format($amount, 2, ',', '.');
                $space = ' ';
                $format = is_string($currency) ? $amount.$space.$currency : $amount;
                break;

            case 'it':
            case 'nl':
                $amount = number_format($amount, 2, ',', '.');
                $space = ' ';
                $format = is_string($currency) ? $currency.$space.$amount : $amount;
                break;

            case 'fr':
                $amount = number_format($amount, 2, ',', ' ');
                $space = ' ';
                $format = is_string($currency) ? $amount.$space.$currency : $amount;
                break;            

            case 'ru':
                $amount = number_format($amount, 2, ',', ' ');
                $space = in_array($currency, $symbols) ? '' : ' ';
                $format = is_string($currency) ? $amount.$space.$currency : $amount;
                break;

            default:
            case 'en':
                $amount = number_format($amount, 2, '.', ',');
                $space = in_array($currency, $symbols) ? '' : ' ';
                $format = is_string($currency) ? $currency.$space.$amount : $amount;
                break;
        }

        return $format;
    }
701924
def truncate(value: Decimal, n_digits: int) -> Decimal:
    """"""
    return Decimal(math.trunc(value * (10 ** n_digits))) / (10 ** n_digits)
1045399
def truncatechars(value,arg=50): 
    '''
    
    ''' 
    arg = int(arg) 
    if arg < len(value): 
        half = (arg-3)/2 
        return "%s...%s" % (value[:half],value[-half:]) 
    return value
131676
private static void decimal(CLDR.Locale locale, String[] numbers, DecimalFormatOptions opts) {
    for (String num : numbers) {
      BigDecimal n = new BigDecimal(num);
      StringBuilder buf = new StringBuilder("  ");
      NumberFormatter fmt = CLDR.get().getNumberFormatter(locale);
      fmt.formatDecimal(n, buf, opts);
      System.out.println(buf.toString());
    }
  }
1049986
def base_convert_money(amount, currency_from, currency_to):
    
    source = get_rate_source()

    # Get rate for currency_from.
    if source.base_currency != currency_from:
        rate_from = get_rate(currency_from)
    else:
        # If currency from is the same as base currency its rate is 1.
        rate_from = Decimal(1)

    # Get rate for currency_to.
    rate_to = get_rate(currency_to)

    if isinstance(amount, float):
        amount = Decimal(amount).quantize(Decimal('.000001'))

    # After finishing the operation, quantize down final amount to two points.
    return ((amount / rate_from) * rate_to).quantize(Decimal("1.00"))
1308435
@Override
    public Money stripTrailingZeros() {
        if (isZero()) {
            return new Money(BigDecimal.ZERO, getCurrency());
        }
        return new Money(this.number.stripTrailingZeros(), getCurrency(), monetaryContext);
    }
708101
def to_money(type='num', point=2)
      str = decimal_point(point).to_s
      int_str = str.split('.')[0]
      point_str = str.split('.')[1]

      return_value = ->() {
        return "#{int_str}.#{point_str}" if point>0
        int_str
      }

      if type=='text'
        return return_value.call if int_str.to_i<10000

        return "#{(int_str.to_i/10000.0).decimal_point(point)}万" if int_str.to_i<100000000

        return "#{(int_str.to_i/100000000.0).decimal_point(point)}亿"
      end

      return return_value.call if int_str.length<3
      index = -4
      while index.abs < int_str.length+1
        int_str.insert(index, ',')
        index -=4
      end
      return_value.call
    end
42507
private static int parseMillis(Input s) {
    if (s.index < s.len && s.getChar() == '.') {
      int startIndex = ++s.index;
      int ms = parseInt(s);
      int len = s.index - startIndex;
      for (; len < 3; len++) ms *= 10;
      for (; len > 3; len--) ms /= 10; // truncate because it's easier than rounding.
      return ms;
    }
    return 0;
  }
1232605
public void deleteCurrency(Currency currency) {
        if (currencyList.containsKey(currency.getName())) {
            Common.getInstance().getStorageHandler().getStorageEngine().deleteCurrency(currency);
            currencyList.remove(currency.getName());
        }
    }
516423
def format_currency(amount, currency)
      
      currency = currency.upcase()
      # assuming that all currencies are split into 100 parts is probably wrong
      # on an i18n scale but it works for USD, EUR and LBP
      # TODO fix this maybe?
      amount = amount / 100.0
      options = {
        # use comma for euro 
        separator: currency == 'EUR' ? ',' : '.', 
        delimiter: currency == 'EUR' ? '.' : ',',
        format: currency == 'EUR' ? '%n %u' : '%u%n',
      }
      case currency
      when 'EUR'
        options[:unit] = '€' 
      when 'LBP'
        options[:unit] = '£'
      when 'USD'
        options[:unit] = '$'
      else
        options[:unit] = currency
      end
      return number_to_currency(amount, options)
    end
1066642
@Override
    public boolean isLessThan(MonetaryAmount amount) {
        MoneyUtils.checkAmountParameter(amount, currency);
        return number.stripTrailingZeros()
                .compareTo(amount.getNumber().numberValue(BigDecimal.class).stripTrailingZeros()) < 0;
    }
1053002
def truncate(data, l=20):
    ""
    info = (data[:l] + '..') if len(data) > l else data
    return info
1019860
public static function amount($amount, $options = []) {
		$amount = trim($amount . '');
		// if currency code is passed we need to load symbol
		if (!empty($options['currency_code'])) {
			if (!isset(self::$cached_currencies)) {
				$temp = \Object\ACL\Resources::getStatic('currencies', 'primary');
				if (!empty($temp)) {
					self::$cached_currencies = $temp;
				} else {
					self::$cached_currencies = [];
				}
			}
			if (!isset($options['symbol']) || (isset($options['symbol']) && $options['symbol'] !== false)) {
				$options['symbol'] = self::$cached_currencies[$options['currency_code']]['symbol'] ?? null;
			}
			// override decimals only if not set
			if (!isset($options['decimals'])) {
				$options['decimals'] = self::$cached_currencies[$options['currency_code']]['fraction_digits'] ?? null;
			}
		}
		// decimals
		if (!isset($options['decimals'])) {
			$options['decimals'] = \Object\Data\Domains::getSetting('amount', 'scale');
		}
		// user defined monetary options
		if (empty($options['skip_user_settings'])) {
			// if type is not set then grab it from settings
			if (!empty($options['type'])) {
				$type = $options['type'];
			} else if (empty($options['fs'])) {
				$type = self::$options['format_amount_frm'];
			} else {
				$type = self::$options['format_amount_fs'];
			}
			if ($type == 10) { // Amount (Locale, With Currency Symbol)
				$options['symbol'] = $options['symbol'] ?? self::$options['locale_options']['currency_symbol'];
			} else if ($type == 20) { // Amount (Locale, Without Currency Symbol)
				$options['symbol'] = false;
			} else if ($type == 30) { // Accounting (Locale, With Currency Symbol)
				$options['symbol'] = $options['symbol'] ?? self::$options['locale_options']['currency_symbol'];
				$options['accounting'] = $options['accounting'] ?? true;
			} else if ($type == 40) { // Accounting (Locale, Without Currency Symbol)
				$options['symbol'] = false;
				$options['accounting'] = $options['accounting'] ?? true;
			} else if ($type == 99) { // Plain Amount
				$options['accounting'] = false;
				$options['symbol'] = false;
				$options['locale_options']['mon_thousands_sep'] = '';
			}
		}
		// formatting if we use locale
		if (self::useLocale()) {
			$amount = self::moneyFormat($amount, $options);
		} else { // if we are not using locale
			if (!empty($options['accounting']) && $amount < 0) {
				$amount = '(' . number_format(abs($amount), $options['decimals'], self::$options['locale_options']['mon_decimal_point'], self::$options['locale_options']['mon_thousands_sep']) . ')';
			} else {
				$amount = number_format($amount, $options['decimals'], self::$options['locale_options']['mon_decimal_point'], self::$options['locale_options']['mon_thousands_sep']);
			}
		}
		return $amount;
	}