Skip to content

🐛 fix(utils): keep tiny prices visible in formatPrice#14235

Merged
tjx666 merged 2 commits into
canaryfrom
fix/format-price-precision
Apr 27, 2026
Merged

🐛 fix(utils): keep tiny prices visible in formatPrice#14235
tjx666 merged 2 commits into
canaryfrom
fix/format-price-precision

Conversation

@tjx666

@tjx666 tjx666 commented Apr 27, 2026

Copy link
Copy Markdown
Member

💻 Change Type

  • 🐛 fix

🔗 Related Issue

N/A — surfaced while reviewing DeepSeek V4 Pro's cache-hit input price card.

🔀 Description of Change

formatPrice always rounds to fractionDigits (default 2) via toFixed, so any positive price under $0.005 collapses to \"0.00\". The model detail panel hits this for any model whose cache-hit price is less than half a cent — DeepSeek V4 Pro's cache-hit input rate ($0.003625 / M tokens) renders as \$0.00 / M tokens, which reads as "free" and is misleading.

Fix: when the price is positive but rounds to zero at the requested precision, expand precision to Math.ceil(-Math.log10(price)) so at least one significant digit is visible:

  • 0.003625\"0.004\"
  • 0.0001\"0.0001\"
  • 0\"0.00\" (unchanged)
  • 0.99 / 1234.56 / 1,000,000.01 (unchanged)

Also collapsed formatSpeed early-returns to silence a long-standing let word = '' ESLint warning that lit up while editing the file.

🧪 How to Test

  • Tested locally
  • Added/updated tests
  • No tests needed

```
cd packages/utils && bunx vitest run --silent='passed-only' src/format.test.ts
```

📝 Additional Information

Pure display-layer change. `formatPrice` is not on any server-side billing path (CostService / spend log / Stripe all consume raw `pricing.units[].rate` numbers); the only non-UI caller in cloud (`subscription/selectors.ts`) feeds dollars-scale values that never trip the new branch.

@vercel

vercel Bot commented Apr 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Canceled Canceled Apr 27, 2026 0:20am

Request Review

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 27, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @tjx666, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@dosubot dosubot Bot added the Bug label Apr 27, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 378fa777d4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/utils/src/format.ts Outdated
@codecov

codecov Bot commented Apr 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.09%. Comparing base (685b17e) to head (aa20ee6).
⚠️ Report is 1 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #14235      +/-   ##
==========================================
- Coverage   68.09%   68.09%   -0.01%     
==========================================
  Files        2266     2266              
  Lines      194349   194343       -6     
  Branches    20344    19559     -785     
==========================================
- Hits       132338   132330       -8     
- Misses      61882    61883       +1     
- Partials      129      130       +1     
Flag Coverage Δ
app 61.59% <ø> (-0.01%) ⬇️
database 92.03% <ø> (ø)
packages/agent-runtime 79.93% <ø> (ø)
packages/context-engine 83.25% <ø> (ø)
packages/conversation-flow 92.40% <ø> (ø)
packages/file-loaders 87.02% <ø> (ø)
packages/memory-user-memory 74.74% <ø> (ø)
packages/model-bank 99.89% <ø> (ø)
packages/model-runtime 84.29% <ø> (ø)
packages/prompts 68.17% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/utils 88.36% <100.00%> (-0.06%) ⬇️
packages/web-crawler 88.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 67.18% <ø> (ø)
Services 53.36% <ø> (ø)
Server 68.44% <ø> (-0.01%) ⬇️
Libs 53.30% <ø> (ø)
Utils 80.04% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tjx666 tjx666 merged commit 94767fd into canary Apr 27, 2026
35 checks passed
@tjx666 tjx666 deleted the fix/format-price-precision branch April 27, 2026 12:20
sxueck pushed a commit to sxueck/lobehub that referenced this pull request Apr 28, 2026
mutoe pushed a commit to mutoe/lobehub that referenced this pull request May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant