(value: DecimalParts, forceDecimal: boolean)
| 420 | } |
| 421 | |
| 422 | function formatParts(value: DecimalParts, forceDecimal: boolean): string { |
| 423 | const normalized = normalizeParts(value); |
| 424 | if (normalized.unscaled === 0n) { |
| 425 | if (normalized.negativeZero) { |
| 426 | return forceDecimal ? "-0.0" : "-0"; |
| 427 | } |
| 428 | return forceDecimal ? "0.0" : "0"; |
| 429 | } |
| 430 | const negative = normalized.unscaled < 0n; |
| 431 | const digits = ( |
| 432 | negative ? -normalized.unscaled : normalized.unscaled |
| 433 | ).toString(); |
| 434 | let result: string; |
| 435 | if (normalized.scale === 0) { |
| 436 | result = forceDecimal ? `${digits}.0` : digits; |
| 437 | } else if (digits.length > normalized.scale) { |
| 438 | const split = digits.length - normalized.scale; |
| 439 | result = `${digits.slice(0, split)}.${digits.slice(split)}`; |
| 440 | } else { |
| 441 | result = `0.${"0".repeat(normalized.scale - digits.length)}${digits}`; |
| 442 | } |
| 443 | return negative ? `-${result}` : result; |
| 444 | } |
| 445 | |
| 446 | function partsEqual(left: DecimalParts, right: DecimalParts): boolean { |
| 447 | const l = normalizeParts(left); |
no test coverage detected