Skip to content

Commit 40b977c

Browse files
cpcloudcursoragent
andcommitted
fix(data): use round(log10(x)) for magnitude notation
The previous formula used floor(log10(x)) which was mathematically incorrect for magnitude notation. The correct formula is round(log10(x)), which better represents the order of magnitude by rounding to the nearest integer power of 10. This affects several display values: - ,234.23: 3 → 4 - 00.00: 2 → 3 - 2.00: 1 → 2 - .50: 0 → 1 - .50: -1 → 0 - .00: 0 → 1 closes #175 Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent faf03d4 commit 40b977c

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

internal/app/mag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func magFormat(c cell, includeUnit bool) string {
6464
return fmt.Sprintf("%s%s%s0", sign, unit, magArrow)
6565
}
6666

67-
mag := int(math.Floor(math.Log10(math.Abs(f))))
67+
mag := int(math.Round(math.Log10(math.Abs(f))))
6868
return fmt.Sprintf("%s%s%s%d", sign, unit, magArrow, mag)
6969
}
7070

internal/app/mag_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ func TestMagFormatMoneyWithUnit(t *testing.T) {
1616
value string
1717
want string
1818
}{
19-
{"thousands", "$5,234.23", "$ \U0001F8213"},
20-
{"hundreds", "$500.00", "$ \U0001F8212"},
19+
{"thousands", "$5,234.23", "$ \U0001F8214"},
20+
{"hundreds", "$500.00", "$ \U0001F8213"},
2121
{"millions", "$1,000,000.00", "$ \U0001F8216"},
2222
{"zero", "$0.00", "$ \U0001F8210"},
23-
{"negative", "-$5.00", "-$ \U0001F8210"},
23+
{"negative", "-$5.00", "-$ \U0001F8211"},
2424
{"negative large", "-$12,345.00", "-$ \U0001F8214"},
2525
}
2626
for _, tt := range tests {
@@ -39,14 +39,14 @@ func TestMagFormatBareMoney(t *testing.T) {
3939
value string
4040
want string
4141
}{
42-
{"thousands", "$5,234.23", "\U0001F8213"},
43-
{"hundreds", "$500.00", "\U0001F8212"},
42+
{"thousands", "$5,234.23", "\U0001F8214"},
43+
{"hundreds", "$500.00", "\U0001F8213"},
4444
{"millions", "$1,000,000.00", "\U0001F8216"},
45-
{"tens", "$42.00", "\U0001F8211"},
46-
{"single digit", "$7.50", "\U0001F8210"},
47-
{"sub-dollar", "$0.50", "\U0001F821-1"},
45+
{"tens", "$42.00", "\U0001F8212"},
46+
{"single digit", "$7.50", "\U0001F8211"},
47+
{"sub-dollar", "$0.50", "\U0001F8210"},
4848
{"zero", "$0.00", "\U0001F8210"},
49-
{"negative", "-$5.00", "-\U0001F8210"},
49+
{"negative", "-$5.00", "-\U0001F8211"},
5050
}
5151
for _, tt := range tests {
5252
t.Run(tt.name, func(t *testing.T) {
@@ -62,7 +62,7 @@ func TestMagFormatDrilldown(t *testing.T) {
6262
value string
6363
want string
6464
}{
65-
{"count", "42", "\U0001F8211"},
65+
{"count", "42", "\U0001F8212"},
6666
{"zero", "0", "\U0001F8210"},
6767
{"large", "1000", "\U0001F8213"},
6868
}
@@ -138,7 +138,7 @@ func TestMagTransformCells(t *testing.T) {
138138
assert.Equal(t, "Deck", out[1][1].Value)
139139

140140
// Money cells: magnitude only ($ stripped by transform).
141-
assert.Equal(t, "\U0001F8213", out[0][2].Value)
141+
assert.Equal(t, "\U0001F8214", out[0][2].Value)
142142
assert.Equal(t, "\U0001F8212", out[1][2].Value)
143143

144144
// Drilldown counts transformed.
@@ -167,8 +167,8 @@ func TestMagModeWorksInEditMode(t *testing.T) {
167167
}
168168

169169
func TestMagCentsIncludesUnit(t *testing.T) {
170-
assert.Equal(t, "$ \U0001F8213", magCents(523423))
171-
assert.Equal(t, "$ \U0001F8212", magCents(50000))
170+
assert.Equal(t, "$ \U0001F8214", magCents(523423))
171+
assert.Equal(t, "$ \U0001F8213", magCents(50000))
172172
assert.Equal(t, "$ \U0001F8210", magCents(100))
173173
}
174174

0 commit comments

Comments
 (0)