Skip to content

Commit 54cb0c8

Browse files
revert: commas in numeric values by default
1 parent a69fae9 commit 54cb0c8

File tree

9 files changed

+53
-144
lines changed

9 files changed

+53
-144
lines changed

internal/ui/component/summary/summary.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ func (m *Model) View() string {
6262
m.styles.TextLabel("Change: ") + quoteChangeText(m.summary.TotalChange.Amount, m.summary.TotalChange.Percent, m.styles)
6363
widthChange := ansi.PrintableRuneWidth(textChange)
6464
textValue := m.styles.TextLabel(" • ") +
65-
m.styles.TextLabel("Value: ") + m.styles.TextLabel(u.ConvertFloatToStringWithCommas(m.summary.Value, false))
65+
m.styles.TextLabel("Value: ") + m.styles.TextLabel(u.ConvertFloatToString(m.summary.Value, false))
6666
widthValue := ansi.PrintableRuneWidth(textValue)
6767
textCost := m.styles.TextLabel(" • ") +
68-
m.styles.TextLabel("Cost: ") + m.styles.TextLabel(u.ConvertFloatToStringWithCommas(m.summary.Cost, false))
68+
m.styles.TextLabel("Cost: ") + m.styles.TextLabel(u.ConvertFloatToString(m.summary.Cost, false))
6969
widthCost := ansi.PrintableRuneWidth(textValue)
7070

7171
return grid.Render(grid.Grid{
@@ -103,12 +103,12 @@ func (m *Model) View() string {
103103

104104
func quoteChangeText(change float64, changePercent float64, styles c.Styles) string {
105105
if change == 0.0 {
106-
return styles.TextLabel(u.ConvertFloatToStringWithCommas(change, false) + " (" + u.ConvertFloatToStringWithCommas(changePercent, false) + "%)")
106+
return styles.TextLabel(u.ConvertFloatToString(change, false) + " (" + u.ConvertFloatToString(changePercent, false) + "%)")
107107
}
108108

109109
if change > 0.0 {
110-
return styles.TextPrice(changePercent, "↑ "+u.ConvertFloatToStringWithCommas(change, false)+" ("+u.ConvertFloatToStringWithCommas(changePercent, false)+"%)")
110+
return styles.TextPrice(changePercent, "↑ "+u.ConvertFloatToString(change, false)+" ("+u.ConvertFloatToString(changePercent, false)+"%)")
111111
}
112112

113-
return styles.TextPrice(changePercent, "↓ "+u.ConvertFloatToStringWithCommas(change, false)+" ("+u.ConvertFloatToStringWithCommas(changePercent, false)+"%)")
113+
return styles.TextPrice(changePercent, "↓ "+u.ConvertFloatToString(change, false)+" ("+u.ConvertFloatToString(changePercent, false)+"%)")
114114
}

internal/ui/component/summary/summary_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var _ = Describe("Summary", func() {
4646
},
4747
}))
4848
Expect(removeFormatting(m.View())).To(Equal(strings.Join([]string{
49-
"Day Change: ↑ 100.00 (10.00%) • Change: ↑ 9,000.00 (1,000.00%) • Value: 10,000.00 • Cost: 1,000.00 ",
49+
"Day Change: ↑ 100.00 (10.00%) • Change: ↑ 9000.00 (1000.00%) • Value: 10000.00 • Cost: 1000.00 ",
5050
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
5151
}, "\n")))
5252
})
@@ -69,7 +69,7 @@ var _ = Describe("Summary", func() {
6969
},
7070
}))
7171
Expect(removeFormatting(m.View())).To(Equal(strings.Join([]string{
72-
"Day Change: ↓ -100.00 (-10.00%) • Change: ↓ -9,000.00 (-1,000.00%) • Value: 1,000.00 • Cost: 10,000.00",
72+
"Day Change: ↓ -100.00 (-10.00%) • Change: ↓ -9000.00 (-1000.00%) • Value: 1000.00 • Cost: 10000.00",
7373
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
7474
}, "\n")))
7575
})

internal/ui/component/watchlist/row/row.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func New(config Config) *Model {
8484
id: id,
8585
width: 80,
8686
config: config,
87-
priceNoChangeSegment: u.ConvertFloatToStringWithCommas(config.Asset.QuotePrice.Price, config.Asset.Meta.IsVariablePrecision),
87+
priceNoChangeSegment: u.ConvertFloatToString(config.Asset.QuotePrice.Price, config.Asset.Meta.IsVariablePrecision),
8888
priceChangeSegment: "",
8989
}
9090
}
@@ -111,8 +111,8 @@ func (m *Model) Update(msg tea.Msg) (*Model, tea.Cmd) {
111111
m.priceStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("15")).Background(lipgloss.Color(""))
112112
m.frame = 0
113113

114-
oldPrice := u.ConvertFloatToStringWithCommas(m.config.Asset.QuotePrice.Price, m.config.Asset.Meta.IsVariablePrecision)
115-
newPrice := u.ConvertFloatToStringWithCommas(msg.QuotePrice.Price, msg.Meta.IsVariablePrecision)
114+
oldPrice := u.ConvertFloatToString(m.config.Asset.QuotePrice.Price, m.config.Asset.Meta.IsVariablePrecision)
115+
newPrice := u.ConvertFloatToString(msg.QuotePrice.Price, msg.Meta.IsVariablePrecision)
116116

117117
if msg.QuotePrice.Price > m.config.Asset.QuotePrice.Price {
118118
m.priceChangeDirection = 1
@@ -147,7 +147,7 @@ func (m *Model) Update(msg tea.Msg) (*Model, tea.Cmd) {
147147

148148
// If symbol has changed or price has not changed then just update the asset
149149
m.config.Asset = msg
150-
m.priceNoChangeSegment = u.ConvertFloatToStringWithCommas(msg.QuotePrice.Price, msg.Meta.IsVariablePrecision)
150+
m.priceNoChangeSegment = u.ConvertFloatToString(msg.QuotePrice.Price, msg.Meta.IsVariablePrecision)
151151
m.priceChangeSegment = ""
152152

153153
return m, nil
@@ -366,7 +366,7 @@ func textPosition(asset *c.Asset, styles c.Styles) string {
366366
positionValue = u.ValueText(asset.Position.Value, styles) +
367367
styles.TextLight(
368368
" ("+
369-
u.ConvertFloatToStringWithCommas(asset.Position.Weight, asset.Meta.IsVariablePrecision)+"%"+
369+
u.ConvertFloatToString(asset.Position.Weight, asset.Meta.IsVariablePrecision)+"%"+
370370
")")
371371
}
372372
if asset.Position.TotalChange.Amount != 0.0 {
@@ -385,19 +385,19 @@ func textQuoteExtended(asset *c.Asset, styles c.Styles) string {
385385
}
386386

387387
if asset.Class == c.AssetClassFuturesContract {
388-
return styles.Text(u.ConvertFloatToStringWithCommas(asset.QuoteFutures.IndexPrice, asset.Meta.IsVariablePrecision)) +
388+
return styles.Text(u.ConvertFloatToString(asset.QuoteFutures.IndexPrice, asset.Meta.IsVariablePrecision)) +
389389
"\n" +
390-
styles.Text(u.ConvertFloatToStringWithCommas(asset.QuoteFutures.Basis, false)) + "%"
390+
styles.Text(u.ConvertFloatToString(asset.QuoteFutures.Basis, false)) + "%"
391391
}
392392

393393
if asset.QuotePrice.PriceOpen == 0.0 {
394-
return styles.Text(u.ConvertFloatToStringWithCommas(asset.QuotePrice.PricePrevClose, asset.Meta.IsVariablePrecision)) +
394+
return styles.Text(u.ConvertFloatToString(asset.QuotePrice.PricePrevClose, asset.Meta.IsVariablePrecision)) +
395395
"\n"
396396
}
397397

398-
return styles.Text(u.ConvertFloatToStringWithCommas(asset.QuotePrice.PricePrevClose, asset.Meta.IsVariablePrecision)) +
398+
return styles.Text(u.ConvertFloatToString(asset.QuotePrice.PricePrevClose, asset.Meta.IsVariablePrecision)) +
399399
"\n" +
400-
styles.Text(u.ConvertFloatToStringWithCommas(asset.QuotePrice.PriceOpen, asset.Meta.IsVariablePrecision))
400+
styles.Text(u.ConvertFloatToString(asset.QuotePrice.PriceOpen, asset.Meta.IsVariablePrecision))
401401

402402
}
403403

@@ -429,9 +429,9 @@ func textPositionExtended(asset *c.Asset, styles c.Styles) string {
429429
return ""
430430
}
431431

432-
return styles.Text(u.ConvertFloatToStringWithCommas(asset.Position.UnitCost, asset.Meta.IsVariablePrecision)) +
432+
return styles.Text(u.ConvertFloatToString(asset.Position.UnitCost, asset.Meta.IsVariablePrecision)) +
433433
"\n" +
434-
styles.Text(u.ConvertFloatToStringWithCommas(asset.Position.Quantity, asset.Meta.IsVariablePrecision))
434+
styles.Text(u.ConvertFloatToString(asset.Position.Quantity, asset.Meta.IsVariablePrecision))
435435

436436
}
437437

@@ -451,9 +451,9 @@ func textQuoteRange(asset *c.Asset, styles c.Styles) string {
451451
if asset.Class == c.AssetClassFuturesContract {
452452

453453
if asset.QuotePrice.PriceDayHigh != 0.0 && asset.QuotePrice.PriceDayLow != 0.0 {
454-
return u.ConvertFloatToStringWithCommas(asset.QuotePrice.PriceDayLow, asset.Meta.IsVariablePrecision) +
454+
return u.ConvertFloatToString(asset.QuotePrice.PriceDayLow, asset.Meta.IsVariablePrecision) +
455455
styles.Text(" - ") +
456-
u.ConvertFloatToStringWithCommas(asset.QuotePrice.PriceDayHigh, asset.Meta.IsVariablePrecision) +
456+
u.ConvertFloatToString(asset.QuotePrice.PriceDayHigh, asset.Meta.IsVariablePrecision) +
457457
"\n" +
458458
asset.QuoteFutures.Expiry
459459
}
@@ -463,13 +463,13 @@ func textQuoteRange(asset *c.Asset, styles c.Styles) string {
463463
}
464464

465465
if asset.QuotePrice.PriceDayHigh != 0.0 && asset.QuotePrice.PriceDayLow != 0.0 {
466-
return u.ConvertFloatToStringWithCommas(asset.QuotePrice.PriceDayLow, asset.Meta.IsVariablePrecision) +
466+
return u.ConvertFloatToString(asset.QuotePrice.PriceDayLow, asset.Meta.IsVariablePrecision) +
467467
styles.Text(" - ") +
468-
u.ConvertFloatToStringWithCommas(asset.QuotePrice.PriceDayHigh, asset.Meta.IsVariablePrecision) +
468+
u.ConvertFloatToString(asset.QuotePrice.PriceDayHigh, asset.Meta.IsVariablePrecision) +
469469
"\n" +
470-
u.ConvertFloatToStringWithCommas(asset.QuoteExtended.FiftyTwoWeekLow, asset.Meta.IsVariablePrecision) +
470+
u.ConvertFloatToString(asset.QuoteExtended.FiftyTwoWeekLow, asset.Meta.IsVariablePrecision) +
471471
styles.Text(" - ") +
472-
u.ConvertFloatToStringWithCommas(asset.QuoteExtended.FiftyTwoWeekHigh, asset.Meta.IsVariablePrecision)
472+
u.ConvertFloatToString(asset.QuoteExtended.FiftyTwoWeekHigh, asset.Meta.IsVariablePrecision)
473473
}
474474

475475
return ""
@@ -501,14 +501,14 @@ func textQuoteRangeLabels(asset *c.Asset, styles c.Styles) string {
501501
func textVolumeMarketCap(asset *c.Asset) string {
502502

503503
if asset.Class == c.AssetClassFuturesContract {
504-
return u.ConvertFloatToStringWithCommas(asset.QuoteFutures.OpenInterest, true) +
504+
return u.ConvertFloatToString(asset.QuoteFutures.OpenInterest, true) +
505505
"\n" +
506-
u.ConvertFloatToStringWithCommas(asset.QuoteExtended.Volume, true)
506+
u.ConvertFloatToString(asset.QuoteExtended.Volume, true)
507507
}
508508

509-
return u.ConvertFloatToStringWithCommas(asset.QuoteExtended.MarketCap, true) +
509+
return u.ConvertFloatToString(asset.QuoteExtended.MarketCap, true) +
510510
"\n" +
511-
u.ConvertFloatToStringWithCommas(asset.QuoteExtended.Volume, true)
511+
u.ConvertFloatToString(asset.QuoteExtended.Volume, true)
512512
}
513513
func textVolumeMarketCapLabels(asset *c.Asset, styles c.Styles) string {
514514

@@ -537,14 +537,14 @@ func textMarketState(asset *c.Asset, styles c.Styles) string {
537537

538538
func quoteChangeText(change float64, changePercent float64, isVariablePrecision bool, styles c.Styles) string {
539539
if change == 0.0 {
540-
return styles.TextPrice(changePercent, " "+u.ConvertFloatToStringWithCommas(change, isVariablePrecision)+" ("+u.ConvertFloatToStringWithCommas(changePercent, false)+"%)")
540+
return styles.TextPrice(changePercent, " "+u.ConvertFloatToString(change, isVariablePrecision)+" ("+u.ConvertFloatToString(changePercent, false)+"%)")
541541
}
542542

543543
if change > 0.0 {
544-
return styles.TextPrice(changePercent, "↑ "+u.ConvertFloatToStringWithCommas(change, isVariablePrecision)+" ("+u.ConvertFloatToStringWithCommas(changePercent, false)+"%)")
544+
return styles.TextPrice(changePercent, "↑ "+u.ConvertFloatToString(change, isVariablePrecision)+" ("+u.ConvertFloatToString(changePercent, false)+"%)")
545545
}
546546

547-
return styles.TextPrice(changePercent, "↓ "+u.ConvertFloatToStringWithCommas(change, isVariablePrecision)+" ("+u.ConvertFloatToStringWithCommas(changePercent, false)+"%)")
547+
return styles.TextPrice(changePercent, "↓ "+u.ConvertFloatToString(change, isVariablePrecision)+" ("+u.ConvertFloatToString(changePercent, false)+"%)")
548548
}
549549

550550
func textSeparator(width int, styles c.Styles) string {

internal/ui/component/watchlist/row/row_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ var _ = Describe("Row", func() {
181181

182182
view := stripANSI(outputRow.View())
183183
Expect(view).To(ContainSubstring("AAPL"), "output was: %q", view)
184-
Expect(view).To(ContainSubstring("1,500.00"), "output was: %q", view)
184+
Expect(view).To(ContainSubstring("1500.00"), "output was: %q", view)
185185
Expect(cmd).ToNot(BeNil())
186186

187187
// Simulate frame updates
@@ -196,7 +196,7 @@ var _ = Describe("Row", func() {
196196
view = stripANSI(outputRow.View())
197197
Expect(cmd).To(BeNil(), "expected cmd to be nil after final frame, got: %v", cmd)
198198
Expect(view).To(ContainSubstring("AAPL"), "output was: %q", view)
199-
Expect(view).To(ContainSubstring("1,500.00"), "output was: %q", view)
199+
Expect(view).To(ContainSubstring("1500.00"), "output was: %q", view)
200200
})
201201

202202
})

internal/ui/component/watchlist/watchlist.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ func getCellWidths(assets []*c.Asset) row.CellWidthsContainer {
206206
for _, asset := range assets {
207207
var quoteLength int
208208

209-
volumeMarketCapLength := len(u.ConvertFloatToStringWithCommas(asset.QuoteExtended.MarketCap, true))
209+
volumeMarketCapLength := len(u.ConvertFloatToString(asset.QuoteExtended.MarketCap, true))
210210

211211
if asset.QuoteExtended.FiftyTwoWeekHigh == 0.0 {
212-
quoteLength = len(u.ConvertFloatToStringWithCommas(asset.QuotePrice.Price, asset.Meta.IsVariablePrecision))
212+
quoteLength = len(u.ConvertFloatToString(asset.QuotePrice.Price, asset.Meta.IsVariablePrecision))
213213
}
214214

215215
if asset.QuoteExtended.FiftyTwoWeekHigh != 0.0 {
216-
quoteLength = len(u.ConvertFloatToStringWithCommas(asset.QuoteExtended.FiftyTwoWeekHigh, asset.Meta.IsVariablePrecision))
216+
quoteLength = len(u.ConvertFloatToString(asset.QuoteExtended.FiftyTwoWeekHigh, asset.Meta.IsVariablePrecision))
217217
}
218218

219219
if volumeMarketCapLength > cellMaxWidths.WidthVolumeMarketCap {
@@ -228,8 +228,8 @@ func getCellWidths(assets []*c.Asset) row.CellWidthsContainer {
228228
}
229229

230230
if asset.Position != (c.Position{}) {
231-
positionLength := len(u.ConvertFloatToStringWithCommas(asset.Position.Value, asset.Meta.IsVariablePrecision))
232-
positionQuantityLength := len(u.ConvertFloatToStringWithCommas(asset.Position.Quantity, asset.Meta.IsVariablePrecision))
231+
positionLength := len(u.ConvertFloatToString(asset.Position.Value, asset.Meta.IsVariablePrecision))
232+
positionQuantityLength := len(u.ConvertFloatToString(asset.Position.Quantity, asset.Meta.IsVariablePrecision))
233233

234234
if positionLength > cellMaxWidths.PositionLength {
235235
cellMaxWidths.PositionLength = positionLength

internal/ui/component/watchlist/watchlist_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ var _ = Describe("Watchlist", func() {
371371
Expect(removeFormatting(m.View())).To(ContainSubstring("Day Range"))
372372
Expect(removeFormatting(m.View())).To(ContainSubstring("52wk Range"))
373373
Expect(removeFormatting(m.View())).To(ContainSubstring("100.00 - 200.00"))
374-
Expect(removeFormatting(m.View())).To(ContainSubstring("300.00 - 2,000.00"))
374+
Expect(removeFormatting(m.View())).To(ContainSubstring("300.00 - 2000.00"))
375375
})
376376

377377
When("there is no day range or open price", func() {
@@ -444,7 +444,7 @@ var _ = Describe("Watchlist", func() {
444444
}
445445
m.Update(SetAssetsMsg(setAssetsMsg))
446446

447-
Expect(removeFormatting(m.View())).To(ContainSubstring("50,312"))
447+
Expect(removeFormatting(m.View())).To(ContainSubstring("50312"))
448448
Expect(removeFormatting(m.View())).To(ContainSubstring("5d 10h"))
449449
Expect(removeFormatting(m.View())).To(ContainSubstring("10.00%"))
450450
})
@@ -506,7 +506,7 @@ var _ = Describe("Watchlist", func() {
506506
m.Update(SetAssetsMsg(setAssetsMsg))
507507

508508
Expect(removeFormatting(m.View())).To(ContainSubstring("Day Range"))
509-
Expect(removeFormatting(m.View())).To(ContainSubstring("49,000.00 - 50,500.00"))
509+
Expect(removeFormatting(m.View())).To(ContainSubstring("49000.00 - 50500.00"))
510510
Expect(removeFormatting(m.View())).To(ContainSubstring("Expiry"))
511511
Expect(removeFormatting(m.View())).To(ContainSubstring("5d 10h"))
512512
})
@@ -582,7 +582,7 @@ var _ = Describe("Watchlist", func() {
582582
m.Update(SetAssetsMsg(setAssetsMsg))
583583
Expect(removeFormatting(m.View())).To(ContainSubstring("Quantity"))
584584
Expect(removeFormatting(m.View())).To(ContainSubstring("Avg. Cost"))
585-
Expect(removeFormatting(m.View())).To(ContainSubstring("92,709.00"))
585+
Expect(removeFormatting(m.View())).To(ContainSubstring("92709.00"))
586586
Expect(removeFormatting(m.View())).To(ContainSubstring("0.00"))
587587
})
588588
})

internal/ui/ui.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,13 @@ func footer(width int, time string, groupSelectedName string, currentSort string
373373
sortDisplayName = "user"
374374
}
375375

376-
helpText := " q: exit ↑: scroll up ↓: scroll down s: change sort (" + sortDisplayName + ") ⭾: change group"
376+
baseHelpText := " q: exit ↑: scroll up ↓: scroll down ⭾: change group"
377+
sortHelpText := " s: change sort (" + sortDisplayName + ")"
378+
379+
// Calculate minimum width for sort help text to appear
380+
// Longest sort text is "s: change sort (change)" = 24 characters
381+
// Minimum width needed: logo(8) + max group(14) + base help(52) + sort help(24) + time(12) = 110
382+
const sortHelpMinWidth = 114
377383

378384
return grid.Render(grid.Grid{
379385
Rows: []grid.Row{
@@ -382,7 +388,8 @@ func footer(width int, time string, groupSelectedName string, currentSort string
382388
Cells: []grid.Cell{
383389
{Text: styleLogo(" ticker "), Width: 8},
384390
{Text: styleGroup(" " + groupSelectedName + " "), Width: len(groupSelectedName) + 2, VisibleMinWidth: 95},
385-
{Text: styleHelp(helpText), Width: len(helpText)},
391+
{Text: styleHelp(baseHelpText), Width: 52},
392+
{Text: styleHelp(sortHelpText), Width: len(sortHelpText), VisibleMinWidth: sortHelpMinWidth},
386393
{Text: styleHelp("↻ " + time), Align: grid.Right},
387394
},
388395
},

internal/ui/util/format.go

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package util
33
import (
44
"math"
55
"strconv"
6-
"strings"
76

87
c "github.com/achannarasappa/ticker/v5/internal/common"
98
)
@@ -35,47 +34,6 @@ func getPrecision(f float64) int {
3534
return 2
3635
}
3736

38-
// addCommaDelimiters adds comma delimiters to the integer part of a number string
39-
func addCommaDelimiters(s string) string {
40-
// Handle negative numbers
41-
isNegative := strings.HasPrefix(s, "-")
42-
if isNegative {
43-
s = s[1:]
44-
}
45-
46-
// Split on decimal point
47-
parts := strings.Split(s, ".")
48-
integerPart := parts[0]
49-
decimalPart := ""
50-
if len(parts) > 1 {
51-
decimalPart = "." + parts[1]
52-
}
53-
54-
// Add commas to integer part
55-
n := len(integerPart)
56-
if n <= 3 {
57-
if isNegative {
58-
return "-" + integerPart + decimalPart
59-
}
60-
61-
return integerPart + decimalPart
62-
}
63-
64-
var result strings.Builder
65-
for i, digit := range integerPart {
66-
if i > 0 && (n-i)%3 == 0 {
67-
result.WriteRune(',')
68-
}
69-
result.WriteRune(digit)
70-
}
71-
72-
if isNegative {
73-
return "-" + result.String() + decimalPart
74-
}
75-
76-
return result.String() + decimalPart
77-
}
78-
7937
// ConvertFloatToString formats a float as a string including handling large or small numbers
8038
func ConvertFloatToString(f float64, isVariablePrecision bool) string {
8139

@@ -105,44 +63,11 @@ func ConvertFloatToString(f float64, isVariablePrecision bool) string {
10563
return strconv.FormatFloat(f, 'f', prec, 64) + unit
10664
}
10765

108-
// ConvertFloatToStringWithCommas formats a float as a string with comma delimiters including handling large or small numbers
109-
func ConvertFloatToStringWithCommas(f float64, isVariablePrecision bool) string {
110-
111-
var unit string
112-
113-
if !isVariablePrecision {
114-
formatted := strconv.FormatFloat(f, 'f', 2, 64)
115-
116-
return addCommaDelimiters(formatted)
117-
}
118-
119-
if f > 1000000000000 {
120-
f /= 1000000000000
121-
unit = " T"
122-
}
123-
124-
if f > 1000000000 {
125-
f /= 1000000000
126-
unit = " B"
127-
}
128-
129-
if f > 1000000 {
130-
f /= 1000000
131-
unit = " M"
132-
}
133-
134-
prec := getPrecision(f)
135-
136-
formatted := strconv.FormatFloat(f, 'f', prec, 64)
137-
138-
return addCommaDelimiters(formatted) + unit
139-
}
140-
14166
// ValueText formats a float as a styled string
14267
func ValueText(value float64, styles c.Styles) string {
14368
if value <= 0.0 {
14469
return ""
14570
}
14671

147-
return styles.Text(ConvertFloatToStringWithCommas(value, false))
72+
return styles.Text(ConvertFloatToString(value, false))
14873
}

0 commit comments

Comments
 (0)