function round(strnum, precision, mode) {
    if (typeof strnum === 'number') {
      strnum = '' + strnum;
    }

    if (typeof strnum !== 'string') {
      throw new Error('expected a string or number, got: ' + strnum);
    }

    if (strnum.length === 0) {
      return strnum;
    }

    if (precision === null || precision === undefined) {
      precision = 0;
    }

    if (mode === undefined) {
      mode = modes.HALF_EVEN;
    }

    var parsed = parse(strnum);

    if (parsed === null) {
      return strnum;
    }

    if (precision > 0) {
      parsed = shiftParts(parsed, precision);
    }

    var _parsed = parsed;

    var _parsed2 = _slicedToArray(_parsed, 3);

    var negative = _parsed2[0];
    var intPart = _parsed2[1];
    var fracPart = _parsed2[2];

    switch (mode) {
      case modes.CEILING:case modes.FLOOR:case modes.UP:
        var foundNonZeroDigit = false;
        for (var i = 0, _length = fracPart.length; i < _length; i++) {
          if (fracPart[i] !== '0') {
            foundNonZeroDigit = true;
            break;
          }
        }
        if (foundNonZeroDigit) {
          if (mode === modes.UP || negative !== (mode === modes.CEILING)) {
            intPart = increment(intPart);
          }
        }
        break;

      case modes.HALF_EVEN:case modes.HALF_DOWN:case modes.HALF_UP:
        var shouldRoundUp = false;
        var firstFracPartDigit = parseInt(fracPart[0], 10);

        if (firstFracPartDigit > 5) {
          shouldRoundUp = true;
        } else if (firstFracPartDigit === 5) {
          if (mode === modes.HALF_UP) {
            shouldRoundUp = true;
          }

          if (!shouldRoundUp) {
            for (var i = 1, _length2 = fracPart.length; i < _length2; i++) {
              if (fracPart[i] !== '0') {
                shouldRoundUp = true;
                break;
              }
            }
          }

          if (!shouldRoundUp && mode === modes.HALF_EVEN) {
            var lastIntPartDigit = parseInt(intPart[intPart.length - 1], 10);
            shouldRoundUp = lastIntPartDigit % 2 !== 0;
          }
        }

        if (shouldRoundUp) {
          intPart = increment(intPart);
        }
        break;
    }

    return format(shiftParts([negative, intPart, ''], -precision));
  }
Round the given number represented by a string according to the given
precision and mode.

@param {string|number} strnum
@param {number|null|undefined=} precision
@param {modes=} mode
@return {string}