lib/utils.js
function roundToPrecision(numStr, scale, fixedDecimalScale) {
  //if number is empty don't do anything return empty string
  if (['', '-'].indexOf(numStr) !== -1) return numStr;
  var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale;

  var _splitDecimal = splitDecimal(numStr),
      beforeDecimal = _splitDecimal.beforeDecimal,
      afterDecimal = _splitDecimal.afterDecimal,
      hasNagation = _splitDecimal.hasNagation;

  var roundedDecimalParts = parseFloat("0.".concat(afterDecimal || '0')).toFixed(scale).split('.');
  var intPart = beforeDecimal.split('').reverse().reduce(function (roundedStr, current, idx) {
    if (roundedStr.length > idx) {
      return (Number(roundedStr[0]) + Number(current)).toString() + roundedStr.substring(1, roundedStr.length);
    }

    return current + roundedStr;
  }, roundedDecimalParts[0]);
  var decimalPart = limitToScale(roundedDecimalParts[1] || '', Math.min(scale, afterDecimal.length), fixedDecimalScale);
  var negation = hasNagation ? '-' : '';
  var decimalSeparator = shoudHaveDecimalSeparator ? '.' : '';
  return "".concat(negation).concat(intPart).concat(decimalSeparator).concat(decimalPart);
}
function roundToPrecision(numStr, scale, fixedDecimalScale) {
  //if number is empty don't do anything return empty string
  if (['', '-'].indexOf(numStr) !== -1) return numStr;
  var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale;

  var _splitDecimal = splitDecimal(numStr),
      beforeDecimal = _splitDecimal.beforeDecimal,
      afterDecimal = _splitDecimal.afterDecimal,
      hasNagation = _splitDecimal.hasNagation;

  var roundedDecimalParts = parseFloat("0.".concat(afterDecimal || '0')).toFixed(scale).split('.');
  var intPart = beforeDecimal.split('').reverse().reduce(function (roundedStr, current, idx) {
    if (roundedStr.length > idx) {
      return (Number(roundedStr[0]) + Number(current)).toString() + roundedStr.substring(1, roundedStr.length);
    }

    return current + roundedStr;
  }, roundedDecimalParts[0]);
  var decimalPart = limitToScale(roundedDecimalParts[1] || '', Math.min(scale, afterDecimal.length), fixedDecimalScale);
  var negation = hasNagation ? '-' : '';
  var decimalSeparator = shoudHaveDecimalSeparator ? '.' : '';
  return "".concat(negation).concat(intPart).concat(decimalSeparator).concat(decimalPart);
}
function roundToPrecision ( numStr , scale , fixedDecimalScale ) { //if number is empty don't do anything return empty string if ( [ '' , '-' ] . indexOf ( numStr ) !== - 1 ) return numStr ; var shoudHaveDecimalSeparator = numStr . indexOf ( '.' ) !== - 1 && scale ; var _splitDecimal = splitDecimal ( numStr ) , beforeDecimal = _splitDecimal . beforeDecimal , afterDecimal = _splitDecimal . afterDecimal , hasNagation = _splitDecimal . hasNagation ; var roundedDecimalParts = parseFloat ( "0." . concat ( afterDecimal || '0' ) ) . toFixed ( scale ) . split ( '.' ) ; var intPart = beforeDecimal . split ( '' ) . reverse ( ) . reduce ( function ( roundedStr , current , idx ) { if ( roundedStr . length > idx ) { return ( Number ( roundedStr [ 0 ] ) + Number ( current ) ) . toString ( ) + roundedStr . substring ( 1 , roundedStr . length ) ; } return current + roundedStr ; } , roundedDecimalParts [ 0 ] ) ; var decimalPart = limitToScale ( roundedDecimalParts [ 1 ] || '' , Math . min ( scale , afterDecimal . length ) , fixedDecimalScale ) ; var negation = hasNagation ? '-' : '' ; var decimalSeparator = shoudHaveDecimalSeparator ? '.' : '' ; return "" . concat ( negation ) . concat ( intPart ) . concat ( decimalSeparator ) . concat ( decimalPart ) ; }
This method is required to round prop value to given scale.
Not used .round or .fixedTo because that will break with big numbers
This method is required to round prop value to given scale . Not used . round or . fixedTo because that will break with big numbers