You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
927 B
2 lines
927 B
"use strict";function h(t,n=15){return+parseFloat(Number(t).toPrecision(n))}function u(t){const n=t.toString().split(/[eE]/),e=(n[0].split(".")[1]||"").length-+(n[1]||0);return e>0?e:0}function s(t){if(t.toString().indexOf("e")===-1)return Number(t.toString().replace(".",""));const n=u(t);return n>0?h(Number(t)*Math.pow(10,n)):Number(t)}function f(t){(t>Number.MAX_SAFE_INTEGER||t<Number.MIN_SAFE_INTEGER)&&console.warn(`${t} 超出了精度限制,结果可能不正确`)}function l(t,n){const[e,r,...o]=t;let i=n(e,r);return o.forEach(c=>{i=n(i,c)}),i}function a(...t){if(t.length>2)return l(t,a);const[n,e]=t,r=s(n),o=s(e),i=u(n)+u(e),c=r*o;return f(c),c/Math.pow(10,i)}function d(...t){if(t.length>2)return l(t,d);const[n,e]=t,r=s(n),o=s(e);return f(r),f(o),a(r/o,h(Math.pow(10,u(e)-u(n))))}function g(t,n){const e=Math.pow(10,n);let r=d(Math.round(Math.abs(a(t,e))),e);return t<0&&r!==0&&(r=a(r,-1)),r}exports.round=g;
|