Skip to content

Fix large decimal price formatting#134

Closed
samsamtrum wants to merge 1 commit into
nktkas:mainfrom
samsamtrum:fix-large-decimal-formatting
Closed

Fix large decimal price formatting#134
samsamtrum wants to merge 1 commit into
nktkas:mainfrom
samsamtrum:fix-large-decimal-formatting

Conversation

@samsamtrum

Copy link
Copy Markdown

Fixes precision loss when formatting very large decimal strings.

StringMath.log10Floor() currently converts the integer portion through Number(...) to decide whether the value is >= 1. For very large decimal strings this loses arbitrary-precision behavior and can also overflow to Infinity, while the rest of the formatter is string-based.

This derives the magnitude directly from string digits instead, and adds a regression test for a large decimal price.

I could not run the Deno test locally because deno is not installed in my environment.

@nktkas

nktkas commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR, but this doesn't change anything in practice:

Number(...) on the integer part only decides whether the value is ≥ 1 — the magnitude comes from the digit count (trimmedInt.length - 1), so its overflow to Infinity never changes the result.
The only inputs where the result actually differs are below ~1e-324, where Number(...) underflows to 0. formatPrice truncates to ≤ 6/8 decimals before log10Floor runs, so it never sees them.

Closing — no reachable behavior change.

@nktkas nktkas closed this Jun 8, 2026
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.

2 participants