(function (global, factory) {
  if (typeof define === "function" && define.amd) {
    define(["exports", "rxjs/operators"], factory);
  } else if (typeof exports !== "undefined") {
    factory(exports, require("rxjs/operators"));
  } else {
    var mod = {
      exports: {}
    };
    factory(mod.exports, global.operators);
    global.roundTo = mod.exports;
  }
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _operators) {
  "use strict";

  Object.defineProperty(_exports, "__esModule", {
    value: true
  });
  _exports.default = void 0;

  function round(number, precision, method) {
    let _number = number;

    if (!Number.isInteger(precision)) {
      throw new Error('Expected precision to be an integer');
    }

    const isRoundingAndNegative = method === 'round' && number < 0;
    if (isRoundingAndNegative) _number = Math.abs(number);
    let exponent;
    [_number, exponent] = `${_number}e`.split('e');
    let result = Math[method](`${_number}e${Number(exponent) + precision}`);
    [_number, exponent] = `${result}e`.split('e');
    result = Number(`${_number}e${Number(exponent) - precision}`);
    if (isRoundingAndNegative) result = -result;
    return result;
  }

  const roundTo = function roundTo(precision = 2) {
    return source$ => source$.pipe((0, _operators.map)(num => round(num, precision, 'round')));
  };

  var _default = roundTo;
  _exports.default = _default;
});
//# sourceMappingURL=roundTo.js.map