decimal128
Version:
Partial implementation of IEEE 754 Decimal128 decimal floating-point numbers
33 lines (26 loc) • 892 B
text/typescript
export function countFractionalDigits(s: string): number {
let [, fractional] = s.split(".");
if (undefined === fractional) {
return 0;
}
return fractional.length;
}
export type Digit = -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; // -1 signals that we're moving from the integer part to the decimal part of a decimal number
export const ROUNDING_MODE_CEILING = "ceil";
export const ROUNDING_MODE_FLOOR = "floor";
export const ROUNDING_MODE_TRUNCATE = "trunc";
export const ROUNDING_MODE_HALF_EVEN = "halfEven";
export const ROUNDING_MODE_HALF_EXPAND = "halfExpand";
export type RoundingMode =
| "ceil"
| "floor"
| "trunc"
| "halfEven"
| "halfExpand";
export const ROUNDING_MODES: RoundingMode[] = [
ROUNDING_MODE_CEILING,
ROUNDING_MODE_FLOOR,
ROUNDING_MODE_TRUNCATE,
ROUNDING_MODE_HALF_EVEN,
ROUNDING_MODE_HALF_EXPAND,
];