MiniDecimal.d.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. export declare type ValueType = string | number;
  2. export interface DecimalClass {
  3. add: (value: ValueType) => DecimalClass;
  4. isEmpty: () => boolean;
  5. isNaN: () => boolean;
  6. isInvalidate: () => boolean;
  7. toNumber: () => number;
  8. /**
  9. * Parse value as string. Will return empty string if `isInvalidate`.
  10. * You can set `safe=false` to get origin string content.
  11. */
  12. toString: (safe?: boolean) => string;
  13. equals: (target: DecimalClass) => boolean;
  14. lessEquals: (target: DecimalClass) => boolean;
  15. negate: () => DecimalClass;
  16. }
  17. /**
  18. * We can remove this when IE not support anymore
  19. */
  20. export declare class NumberDecimal implements DecimalClass {
  21. origin: string;
  22. number: number;
  23. empty: boolean;
  24. constructor(value: ValueType);
  25. negate(): NumberDecimal;
  26. add(value: ValueType): NumberDecimal;
  27. isEmpty(): boolean;
  28. isNaN(): boolean;
  29. isInvalidate(): boolean;
  30. equals(target: DecimalClass): boolean;
  31. lessEquals(target: DecimalClass): boolean;
  32. toNumber(): number;
  33. toString(safe?: boolean): string;
  34. }
  35. export declare class BigIntDecimal implements DecimalClass {
  36. origin: string;
  37. negative: boolean;
  38. integer: bigint;
  39. decimal: bigint;
  40. /** BigInt will convert `0009` to `9`. We need record the len of decimal */
  41. decimalLen: number;
  42. empty: boolean;
  43. nan: boolean;
  44. constructor(value: string | number);
  45. private getMark;
  46. private getIntegerStr;
  47. private getDecimalStr;
  48. /**
  49. * Align BigIntDecimal with same decimal length. e.g. 12.3 + 5 = 1230000
  50. * This is used for add function only.
  51. */
  52. private alignDecimal;
  53. negate(): BigIntDecimal;
  54. add(value: ValueType): BigIntDecimal;
  55. isEmpty(): boolean;
  56. isNaN(): boolean;
  57. isInvalidate(): boolean;
  58. equals(target: DecimalClass): boolean;
  59. lessEquals(target: DecimalClass): boolean;
  60. toNumber(): number;
  61. toString(safe?: boolean): string;
  62. }
  63. export default function getMiniDecimal(value: ValueType): DecimalClass;
  64. /**
  65. * round up an unsigned number str, like: 1.4 -> 2, 1.5 -> 2
  66. */
  67. export declare function roundUpUnsignedDecimal(numStr: string, precision: number): any;
  68. /**
  69. * round up an unsigned number str, like: 1.4 -> 1, 1.5 -> 1
  70. */
  71. export declare function roundDownUnsignedDecimal(numStr: string, precision: number): string;
  72. /**
  73. * Align the logic of toFixed to around like 1.5 => 2
  74. */
  75. export declare function toFixed(numStr: string, separatorStr: string, precision?: number): any;