Skip to content

fix: handle tiny exponential values in formatNumber - #251

Open
DeoJin wants to merge 1 commit into
openexchangerates:masterfrom
DeoJin:fix-formatnumber-tiny-values-241
Open

fix: handle tiny exponential values in formatNumber#251
DeoJin wants to merge 1 commit into
openexchangerates:masterfrom
DeoJin:fix-formatnumber-tiny-values-241

Conversation

@DeoJin

@DeoJin DeoJin commented Mar 18, 2026

Copy link
Copy Markdown

Summary

  • handle exponent-notation inputs in toFixed() by falling back to native Number(...).toFixed()
  • fix formatNumber() for very small values like 1e-7 so it returns a formatted zero instead of NaN
  • add regression coverage for tiny positive and negative values

Closes #241.

Validation

  • node -e "const accounting=require('./accounting'); function assertEq(actual, expected, label){ if(actual!==expected){ console.error(label + ': expected ' + expected + ', got ' + actual); process.exit(1);} } assertEq(accounting.formatNumber(0.615, 2), '0.62', 'rounding regression'); assertEq(accounting.formatNumber(1.005, 2), '1.01', 'rounding regression 2'); assertEq(accounting.formatNumber(1e-7, 2), '0.00', 'tiny positive'); assertEq(accounting.formatNumber(0.0000001, 6), '0.000000', 'tiny precision'); assertEq(accounting.formatNumber(-3e-23, 2), '-0.00', 'tiny negative'); console.log('validation-ok');"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tiny numbers lead to NaN.undefined

1 participant