Skip to content

Commit e55ed10

Browse files
committed
fix: fix FormatFloat function
1 parent f95ad66 commit e55ed10

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

Diff for: pkg/utils/view.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func SizeByteToGB(v *int32) string {
8181
return fmt.Sprintf("%d GB", vv)
8282
}
8383

84-
func FormatFloat(number float64) string {
84+
func FormatPriceFloat(number float64) string {
8585
isNegative := false
8686
if number < 0 {
8787
isNegative = true
@@ -99,8 +99,8 @@ func FormatFloat(number float64) string {
9999
result = append(result, rune(digit))
100100
}
101101
if isNegative {
102-
return fmt.Sprintf("-%s.%s", string(result), decimalPart)
102+
return fmt.Sprintf("-$%s.%s", string(result), decimalPart)
103103
} else {
104-
return fmt.Sprintf("%s.%s", string(result), decimalPart)
104+
return fmt.Sprintf("$%s.%s", string(result), decimalPart)
105105
}
106106
}

Diff for: view/non_interactive_view.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func getItemString(item *golang.OptimizationItem) string {
123123
totalSaving += dev.CurrentCost - dev.RightSizedCost
124124
}
125125
}
126-
row = append(row, item.Id, item.ResourceType, item.Region, item.Platform, fmt.Sprintf("$%s", utils.FormatFloat(totalSaving)))
126+
row = append(row, item.Id, item.ResourceType, item.Region, item.Platform, fmt.Sprintf("%s", utils.FormatPriceFloat(totalSaving)))
127127
t.AppendRow(row)
128128
itemString += t.Render()
129129
itemString += "\n " + bold.Sprint("Devices") + ":"
@@ -197,7 +197,7 @@ func getDeviceString(dev *golang.Device) string {
197197
t.AppendHeader(headers)
198198
var row table.Row
199199
var itemString string
200-
row = append(row, "└─ "+dev.DeviceId, dev.ResourceType, dev.Runtime, dev.CurrentCost, dev.RightSizedCost, fmt.Sprintf("$%s", utils.FormatFloat(dev.CurrentCost-dev.RightSizedCost)))
200+
row = append(row, "└─ "+dev.DeviceId, dev.ResourceType, dev.Runtime, dev.CurrentCost, dev.RightSizedCost, fmt.Sprintf("%s", utils.FormatPriceFloat(dev.CurrentCost-dev.RightSizedCost)))
201201
t.AppendRow(row)
202202
itemString += t.Render()
203203
itemString += "\n " + bold.Sprint("Properties") + ":\n" + getPropertiesString(dev.Properties)
@@ -425,8 +425,8 @@ func exportCsv(items []*golang.OptimizationItem) ([]string, [][]string) {
425425
for _, d := range i.Devices {
426426
for _, p := range d.Properties {
427427
rows = append(rows, []string{
428-
i.Id, i.ResourceType, i.Region, i.Platform, fmt.Sprintf("$%s", utils.FormatFloat(totalSaving)),
429-
d.DeviceId, d.ResourceType, d.Runtime, fmt.Sprintf("$%s", utils.FormatFloat(d.CurrentCost)), fmt.Sprintf("$%s", utils.FormatFloat(d.RightSizedCost)), fmt.Sprintf("$%s", utils.FormatFloat(d.CurrentCost-d.RightSizedCost)),
428+
i.Id, i.ResourceType, i.Region, i.Platform, fmt.Sprintf("%s", utils.FormatPriceFloat(totalSaving)),
429+
d.DeviceId, d.ResourceType, d.Runtime, fmt.Sprintf("%s", utils.FormatPriceFloat(d.CurrentCost)), fmt.Sprintf("%s", utils.FormatPriceFloat(d.RightSizedCost)), fmt.Sprintf("%s", utils.FormatPriceFloat(d.CurrentCost-d.RightSizedCost)),
430430
p.Key, p.Current, p.Average, p.Max, p.Recommended,
431431
})
432432
}

Diff for: view/page_optimization.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (m OptimizationsPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9191
i.ResourceType,
9292
i.Region,
9393
i.Platform,
94-
fmt.Sprintf("$%s (%.2f%%)", utils.FormatFloat(totalSaving), (totalSaving/totalCurrentCost)*100),
94+
fmt.Sprintf("%s (%.2f%%)", utils.FormatPriceFloat(totalSaving), (totalSaving/totalCurrentCost)*100),
9595
}
9696
if i.Skipped {
9797
row[5] = "skipped"
@@ -210,7 +210,7 @@ func (m OptimizationsPage) View() string {
210210
}
211211

212212
return fmt.Sprintf("Current runtime cost: %s, Savings: %s\n%s\n%s",
213-
style.CostStyle.Render(fmt.Sprintf("$%s", utils.FormatFloat(totalCost))), style.SavingStyle.Render(fmt.Sprintf("$%s", utils.FormatFloat(savings))),
213+
style.CostStyle.Render(fmt.Sprintf("%s", utils.FormatPriceFloat(totalCost))), style.SavingStyle.Render(fmt.Sprintf("%s", utils.FormatPriceFloat(savings))),
214214
m.table.View(),
215215
m.statusBar.View(),
216216
)

Diff for: view/page_optimization_details.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ func (m OptimizationDetailsPage) OnOpen() Page {
127127
item.Name,
128128
dev.ResourceType,
129129
dev.Runtime,
130-
fmt.Sprintf("$%s", utils.FormatFloat(dev.CurrentCost)),
130+
fmt.Sprintf("%s", utils.FormatPriceFloat(dev.CurrentCost)),
131131
ifRecommendationExists(func() string {
132-
return fmt.Sprintf("$%s", utils.FormatFloat(dev.RightSizedCost))
132+
return fmt.Sprintf("%s", utils.FormatPriceFloat(dev.RightSizedCost))
133133
}),
134134
ifRecommendationExists(func() string {
135-
return fmt.Sprintf("$%s", utils.FormatFloat(dev.CurrentCost-dev.RightSizedCost))
135+
return fmt.Sprintf("%s", utils.FormatPriceFloat(dev.CurrentCost-dev.RightSizedCost))
136136
}),
137137
})
138138
}

0 commit comments

Comments
 (0)