Given two Decimals, return a 9-filled decimal representing both enough > 0 digits
    and enough < 0 digits (scale) to accomodate numbers like either.

    >>> worst_decimal(Decimal('762.1'), Decimal('-1.983'))
    Decimal('999.999')
509343
def worst_decimal(d1, d2):
    
    (d1b4, d1after) = _places_b4_and_after_decimal(d1)
    (d2b4, d2after) = _places_b4_and_after_decimal(d2)
    return Decimal('9' * max(d1b4, d2b4) + '.' + '9' * max(d1after, d2after))
1032654
def ratio(value, decimal_places=0, failure_string='N/A'):
    
    try:
        f = float(value)
    except ValueError:
        return failure_string
    return _saferound(f, decimal_places) + ':1'
1018773
def format_decimal_field(__, prec, number, locale):
    
    prec = 0 if prec is None else int(prec)
    if number < 0:
        prec += 1
    return format(number, u'0%dd' % prec)
588313
def binary_float_to_decimal_float(number: Union[float, str]) -> float:
    
    if isinstance(number, str):
        if number[0] == '-':
            n_sign = -1
        else:
            n_sign = 1
    elif isinstance(number, float):
        n_sign = np.sign(number)
        number = str(number)

    deci = 0
    for ndx, val in enumerate(number.split('.')[-1]):
        deci += float(val) / 2**(ndx+1)
    deci *= n_sign

    return deci
1028796
def decimals(self):
        
        self._decimals, value = self.get_attr_int(self._decimals, 'decimals')
        return value
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)
133148
def _bits_to_float(bits, lower=-90.0, middle=0.0, upper=90.0):
  """"""
  for i in bits:
    if i:
      lower = middle
    else:
      upper = middle
    middle = (upper + lower) / 2
  return middle
283182
def quantize(self, value):
        
        context = decimal.getcontext().copy()
        context.prec = self.max_digits
        return value.quantize(
            decimal.Decimal('.1') ** self.decimal_places,
            context=context)
915806
function calculateMaxValue(precision, scale) {
  const arr = _.fill(Array(precision), '9');

  if (scale) {
    arr.splice(precision - scale, 0, '.');
  }

  return parseFloat(arr.join(''));
}
638214
def quantize(number, digits=0, q=builtins.round):
    
    base, fraction = split(digits)

    # quantization beyond an order of magnitude results in a variable amount
    # of decimal digits depending on the lowest common multiple,
    # e.g. floor(1.2341234, 1.25) = 1.225 but floor(1.2341234, 1.5) = 1.20
    if fraction * 10 % 1 > 0:
        digits = base + 2
    else:
        digits = base + 1

    multiplier = 10 ** base * invert(fraction, default=1)
    quantized = q(number * multiplier) / multiplier

    # additional rounding step to get rid of floating point math wonkiness
    return builtins.round(quantized, digits)
531051
def decimal(self, column, total=8, places=2):
        
        return self._add_column("decimal", column, total=total, places=places)
620674
def round(value, decimal=7, digits=None):
    
    if value == None:
        return None
    else:
        value = float(value)

    if digits != None:
        if digits <= 0:
            if value == 0:
                return int(_round(value, digits))
            try:
                m = pow(10, math_ceil(math_log10(abs(value))))
                return int(_round(value / m, digits) * m)
            except Exception as e:
                from mo_logs import Log

                Log.error("not expected", e)
        else:
            if value == 0:
                return _round(value, digits)
            try:
                m = pow(10, math_ceil(math_log10(abs(value))))
                return _round(value / m, digits) * m
            except Exception as e:
                from mo_logs import Log
                Log.error("not expected", e)
    elif decimal <= 0:
        return int(_round(value, decimal))
    else:
        return _round(value, decimal)
509536
def round_two_non_zero_dp(decimal):
    
    log10 = decimal.log10().to_integral_exact(rounding=ROUND_FLOOR) \
        if decimal else 0
    div = Decimal(10) ** (Decimal(1) - log10) if log10 < 0 else Decimal(100)
    return (decimal * div).to_integral_exact(rounding=ROUND_HALF_UP) / div
1038339
def rounding(price, currency):
	
	currency = validate_currency(currency)
	price = validate_price(price)
	if decimals(currency) == 0:
		return round(int(price), decimals(currency))
	return round(price, decimals(currency))
168624
def round(self, digits=0):
        
        self._left = round(self._left, digits)
        self._bottom = round(self._bottom, digits)
        self._width = round(self._width, digits)
        self._height = round(self._height, digits)
891182
def _places_b4_and_after_decimal(d):
    
    tup = d.as_tuple()
    return (len(tup.digits) + tup.exponent, max(-1*tup.exponent, 0))
246197
def decimal(self, prompt, default=None, lower=None, upper=None):
        """"""
        prompt = prompt if prompt is not None else "Enter a decimal number"
        prompt += " [{0}]: ".format(default) if default is not None else ': '
        return self.input(
            curry(filter_decimal, default=default, lower=lower, upper=upper),
            prompt
        )