Skip to content

fix: handle tiny values in toFixed - #250

Open
DeoJin wants to merge 1 commit into
openexchangerates:masterfrom
DeoJin:fix/issue-233
Open

fix: handle tiny values in toFixed#250
DeoJin wants to merge 1 commit into
openexchangerates:masterfrom
DeoJin:fix/issue-233

Conversation

@DeoJin

@DeoJin DeoJin commented Mar 18, 2026

Copy link
Copy Markdown

Summary

  • fix toFixed so exponential-notation inputs are shifted correctly before and after rounding
  • add regression coverage for tiny exponential-form values in both Jasmine and QUnit suites
  • preserve existing rounding behavior for normal decimal inputs

Testing

  • node -e "const accounting=require('./accounting.js'); const cases=[[accounting.toFixed('-0.00000000000000000000003',2),'0.00'],[accounting.toFixed('-0.00000000000000000000003',23),'-0.00000000000000000000003'],[accounting.formatNumber(1e-7,2),'0.00'],[accounting.formatNumber(1e-7,8),'0.00000010'],[accounting.toFixed(0.615,2),'0.62'],[accounting.toFixed(574.425,2),'574.43']]; for (const [actual, expected] of cases) { if (actual !== expected) { console.error(JSON.stringify({actual, expected})); process.exit(1);} } console.log('node-assertions: ok');"

Fixes #233

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.

toFixed does not play well with long decimal values.

1 participant