Takes a decimal price and rounds to a number of decimal places
329791
def price_rounding(price, decimals=2):
    """"""
    try:
        exponent = D('.' + decimals * '0')
    except InvalidOperation:
        # Currencies with no decimal places, ex. JPY, HUF
        exponent = D()
    return price.quantize(exponent, rounding=ROUND_UP)
269283
def convert_value(self, value):
        """"""
        if isinstance(value, str):
            value = value.replace(self.separator, '')
            if self.decimal_point not in value:
                return int(value)
            else:
                return float(value.replace(self.decimal_point, '.'))
        elif self.int_to_float:
            return float(value)
        else:
            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());
    }
  }
121059
def _recursive_round(self, value, precision):
        
        if hasattr(value, '__iter__'):
            return tuple(self._recursive_round(v, precision) for v in value)
        return round(value, precision)
537345
def round_to_n_decimal_places(array, n=3):
    
    # check if in scientific notation
    if issubclass(array.__class__, float) and '%.e'%array == str(array):
        return array # do nothing

    shape = np.shape(array)
    out = ((np.atleast_1d(array) * 10**n).round().astype('int') / (10.**n))
    return out.reshape(shape)
799844
function roundToNumber(num, place) {
    var newval=1*num;

    if(typeof(newval)=="number"){
      if(place<=0){
        var roundVal=-place;
        newval= +(Math.round(newval + "e+" + roundVal) + "e-" + roundVal);
      }
      else {
        var roundVal=place;
        var divval= "1e+"+roundVal;
        newval= +(Math.round(newval/divval))*divval;
      }
    }
    return(newval);
}
1108033
def round_float(float, places)
      factor = Float(10 * places)
      Float((float * factor).round / factor)
    end
214817
def fixed(value, places = 2)
      value = value.to_s.to_f unless value.is_a?(Float)
      sprintf("%0.#{places}f", value.round(places))
    end
754544
def fix_decimals(obj):
    
    if isinstance(obj, list):
        for i in range(len(obj)):
            obj[i] = fix_decimals(obj[i])
        return obj

    elif isinstance(obj, dict):
        for key, value in obj.items():
            obj[key] = fix_decimals(value)
        return obj

    elif isinstance(obj, decimal.Decimal):
        if obj % 1 == 0:
            return int(obj)
        else:
            return float(obj)

    else:
        return obj
967728
def roundup(x, order):
    '''
    '''
    return x if x % 10**order == 0 else x + 10**order - x % 10**order
706025
def trunc(ctx, number):
    
    return conversions.to_integer(conversions.to_decimal(number, ctx).to_integral_value(ROUND_DOWN), ctx)
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
377981
def round_float(f, digits, rounding=ROUND_HALF_UP):
    
    return Decimal(str(f)).quantize(Decimal(10) ** (-1 * digits),
                                    rounding=rounding)
860021
def round_to_float(number, precision):
    """"""
    rounded = Decimal(str(floor((number + precision / 2) // precision))
                      ) * Decimal(str(precision))
    return float(rounded)
650429
def _float_to_bits(value, lower=-90.0, middle=0.0, upper=90.0, length=15):
  """"""
  ret = []
  for i in range(length):
    if value >= middle:
      lower = middle
      ret.append(1)
    else:
      upper = middle
      ret.append(0)
    middle = (upper + lower) / 2
  return ret
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)
1110069
def round_to_int(number, precision):
    """"""
    precision = int(precision)
    rounded = (int(number) + precision / 2) // precision * precision
    return rounded