Skip to content

fix: handle tiny scientific-notation values in formatNumber#249

Open
DeoJin wants to merge 1 commit into
openexchangerates:masterfrom
DeoJin:fix/issue-241-tiny-number-formatting
Open

fix: handle tiny scientific-notation values in formatNumber#249
DeoJin wants to merge 1 commit into
openexchangerates:masterfrom
DeoJin:fix/issue-241-tiny-number-formatting

Conversation

@DeoJin

@DeoJin DeoJin commented Mar 17, 2026

Copy link
Copy Markdown

Summary

  • make toFixed() handle values that are already represented in scientific notation
  • preserve existing rounding behavior for normal decimal inputs
  • add a regression spec for very small numbers that previously formatted as NaN

Validation

  • node -e "const assert=require('assert'); const accounting=require('./accounting'); assert.strictEqual(accounting.formatNumber(1e-7), '0'); assert.strictEqual(accounting.formatNumber(0.0000001), '0'); assert.strictEqual(accounting.formatNumber(1e-7, 8), '0.00000010'); assert.strictEqual(accounting.formatNumber(0.615, 2), '0.62'); assert.strictEqual(accounting.formatNumber(123456.54321, 2), '123,456.54'); console.log('validation ok');"

Fixes #241

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