fixed-base.ts 345 B

1234567891011121314
  1. const fixedBase = function(v: number, base: number | string): number {
  2. const str = base.toString();
  3. const index = str.indexOf('.');
  4. if (index === -1) {
  5. return Math.round(v);
  6. }
  7. let length = str.substr(index + 1).length;
  8. if (length > 20) {
  9. length = 20;
  10. }
  11. return parseFloat(v.toFixed(length));
  12. };
  13. export default fixedBase;