UNPKG

round-decimal

Version:
2 lines (1 loc) 696 B
(function(i,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(i=typeof globalThis<"u"?globalThis:i||self,n(i.roundDecimal={}))})(this,function(i){"use strict";function n(t){return Math.pow(2,Math.ceil(Math.log2(Math.abs(t)))-52)}function a(t){return Math.trunc(Math.abs(Math.log10(n(t))))}const o=3;function c(t,u=o){const e=a(t);if(e<u)return t;const f=t<0?-Math.pow(10,e):Math.pow(10,e);return Math.round(t*f)/f}i.approximateUlp=n,i.default=c,i.defaultMinSignificantFractionDigits=o,i.getSignificantFractionDigits=a,i.roundDecimal=c,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});