(val: string)
| 216 | * - Decimal strings are normalized to minimum 2 decimal places, stripping excess trailing zeros |
| 217 | */ |
| 218 | export function normalizeDecimalDefault(val: string): (ab: ExpressionBuilder) => AstFactory<Expression> { |
| 219 | if (/^-?\d+$/.test(val)) { |
| 220 | return (ab) => ab.NumberLiteral.setValue(val + '.00'); |
| 221 | } |
| 222 | if (/^-?\d+\.\d+$/.test(val)) { |
| 223 | const [integerPart, fractionalPart] = val.split('.'); |
| 224 | let normalized = fractionalPart!.replace(/0+$/, ''); |
| 225 | if (normalized.length < 2) { |
| 226 | normalized = normalized.padEnd(2, '0'); |
| 227 | } |
| 228 | return (ab) => ab.NumberLiteral.setValue(`${integerPart}.${normalized}`); |
| 229 | } |
| 230 | return (ab) => ab.NumberLiteral.setValue(val); |
| 231 | } |
no test coverage detected