Round a number or a float to a precision
962295
def round_to_scale(number, precision):
    """"""
    if precision < 1:
        return round_to_float(number, precision)
    return round_to_int(number, precision)
740944
def si_round(val):
    '''
    
    '''
    if val < 0:
        neg = True
        val = -val
    elif val == 0:
        return 0, 0
    else:
        neg = False
    exp = math.log(val) / math.log(1000)
    if exp < 0:
        exp = int(exp) - 1
    else:
        exp = int(exp)
    val = val / 1000.0 ** exp
    if neg:
        val = -val
    return val, 3 * exp
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
858646
public static float round(Float number, int precision) {
        return (float)(Math.floor(number.doubleValue()*Math.pow(10,precision)+0.5)/Math.pow(10,precision));
    }
26415
def precision(self, label=None):
        
        if label is None:
            return self.call("precision")
        else:
            return self.call("precision", float(label))
314496
def rounded(self, number, roundto=None):
        
        if roundto is None:
            roundto = self.roundTo()
        
        if not roundto:
            return number
    
        remain = number % roundto
        if remain:
            return number + (roundto - remain)
        return number
1135173
public static float trunc(Float number, int precision) {
        return (float)(Math.floor(number.doubleValue()*Math.pow(10,precision))/Math.pow(10,precision));
    }
501986
def _q(self, number, precision='.00001'):
        """"""
        if np.isinf(number):
            return np.nan
        else:
            return D(D(number).quantize(D(precision)))
877691
def round(self):
    """"""
    return Point(int(round(self.x)), int(round(self.y)))
1340074
def toint(number):
    
    if isinstance(number, float):
        number = round(number, 0)
    return int(number)
795209
def _unfloat(flt, precision=5):
    

    if flt == 0.:
        return "{}-0".format("0" * precision)

    num, _, exp = "{:.{}e}".format(flt, precision - 1).partition('e')
    exp = int(exp)
    num = num.replace('.', '')

    return "%s%d" % (num, exp + 1)
237128
def round_figures(x, n):
    """"""
    return round(x, int(n - math.ceil(math.log10(abs(x)))))
1136516
public function toDecimal($value, int $precision = 12): float
    {
        if (is_numeric($value) === false) {
            return 0.0;
        }

        return round((float) $value, $precision);
    }
1246908
public static float trunc(Float number, int precision) {
        if (number < 0f) {
            return (float)(Math.ceil(number.doubleValue()*Math.pow(10,precision))/Math.pow(10,precision));
        }
        return (float)(Math.floor(number.doubleValue()*Math.pow(10,precision))/Math.pow(10,precision));
    }
915806
function calculateMaxValue(precision, scale) {
  const arr = _.fill(Array(precision), '9');

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

  return parseFloat(arr.join(''));
}
720453
function(num, dec) {
      var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
      return result;
    }
1334876
def to_percentage(number, rounding=2):
    
    number = float(number) * 100
    number_as_int = int(number)
    rounded = round(number, rounding)

    return '{}%'.format(number_as_int if number_as_int == rounded else rounded)