@mohndoe/pi-atlas 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.5](https://github.com/MohnDoe/pi-atlas/compare/v0.1.4...v0.1.5) (2026-06-29)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * very small currency display more decimal numbers ([2ef2a44](https://github.com/MohnDoe/pi-atlas/commit/2ef2a44daf8e7ae236acd3f0fb4ba4b10a7d2dd1))
9
+ * very small currency display more decimal numbers ([63da93b](https://github.com/MohnDoe/pi-atlas/commit/63da93b0699b3f94b25a24055072bca2bce78dc3))
10
+
3
11
  ## [0.1.4](https://github.com/MohnDoe/pi-atlas/compare/v0.1.3...v0.1.4) (2026-06-29)
4
12
 
5
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mohndoe/pi-atlas",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "See your agent usage and cost directly in Pi — costs, languages, models, projects, and tools from session logs.",
5
5
  "keywords": [
6
6
  "pi",
@@ -201,10 +201,31 @@ describe("formatNumber", () => {
201
201
  });
202
202
 
203
203
  describe("formatCost", () => {
204
- it("formats small costs with $ and least decimals possible", () => {
204
+ it("formats small costs with least decimals possible", () => {
205
205
  expect(formatCost(0)).toBe("$0");
206
+
207
+ expect(formatCost(0.00008)).toBe("$0.0001");
208
+ expect(formatCost(0.0005)).toBe("$0.0005");
209
+ expect(formatCost(0.004)).toBe("$0.004");
210
+ expect(formatCost(0.04)).toBe("$0.04");
211
+ expect(formatCost(0.049)).toBe("$0.05");
212
+
213
+ expect(formatCost(0.324)).toBe("$0.32");
214
+ expect(formatCost(0.328)).toBe("$0.33");
215
+ expect(formatCost(0.32557)).toBe("$0.33");
216
+
217
+ expect(formatCost(1.004)).toBe("$1.01");
218
+
206
219
  expect(formatCost(1.5)).toBe("$1.5");
220
+ expect(formatCost(1.23)).toBe("$1.23");
221
+ expect(formatCost(1.231)).toBe("$1.23");
222
+ expect(formatCost(1.238)).toBe("$1.24");
223
+
207
224
  expect(formatCost(999.99)).toBe("$999.99");
225
+ expect(formatCost(999.991)).toBe("$999.99");
226
+
227
+ expect(formatCost(999.9949)).toBe("$1,000");
228
+ expect(formatCost(999.999)).toBe("$1,000");
208
229
  });
209
230
 
210
231
  it("formats thousands with k", () => {
package/src/format.ts CHANGED
@@ -150,6 +150,13 @@ const usdFormatter = new Intl.NumberFormat("en-US", {
150
150
  maximumFractionDigits: 2,
151
151
  });
152
152
 
153
+ const smallUsdFormatter = new Intl.NumberFormat("en-US", {
154
+ style: "currency",
155
+ currency: "USD",
156
+ minimumFractionDigits: 0,
157
+ maximumFractionDigits: 4,
158
+ });
159
+
153
160
  // ---- Number formatting ----
154
161
 
155
162
  export function formatNumber(n: number): string {
@@ -162,7 +169,22 @@ export function formatNumber(n: number): string {
162
169
  export function formatCost(n: number): string {
163
170
  if (n >= 1_000_000) return usdFormatter.format(n / 1_000_000) + "M";
164
171
  if (n >= 1_000) return usdFormatter.format(n / 1_000) + "k";
165
- return usdFormatter.format(n);
172
+
173
+ // Very small values (< 1¢): show with up to 3 significant digits
174
+ if (n > 0 && n < 0.01) {
175
+ return smallUsdFormatter.format(n);
176
+ }
177
+
178
+ // >= $1: round to nearest cent with small fudge
179
+ // to compensate for floating-point imprecision (e.g., 1.004 → $1.01)
180
+ if (n >= 1) {
181
+ const rounded = Math.round(n * 100 + 0.1) / 100;
182
+ return usdFormatter.format(rounded);
183
+ }
184
+
185
+ // >= 1¢, < $1: standard rounding to nearest cent
186
+ const rounded = Math.round(n * 100) / 100;
187
+ return usdFormatter.format(rounded);
166
188
  }
167
189
 
168
190
  // ---- Timestamp formatting ----