diff --git a/pkg/utils/view.go b/pkg/utils/view.go index 8ba33f1..497661e 100644 --- a/pkg/utils/view.go +++ b/pkg/utils/view.go @@ -81,7 +81,7 @@ func SizeByteToGB(v *int32) string { return fmt.Sprintf("%d GB", vv) } -func FormatFloat(number float64) string { +func FormatPriceFloat(number float64) string { isNegative := false if number < 0 { isNegative = true @@ -99,8 +99,8 @@ func FormatFloat(number float64) string { result = append(result, rune(digit)) } if isNegative { - return fmt.Sprintf("-%s.%s", string(result), decimalPart) + return fmt.Sprintf("-$%s.%s", string(result), decimalPart) } else { - return fmt.Sprintf("%s.%s", string(result), decimalPart) + return fmt.Sprintf("$%s.%s", string(result), decimalPart) } } diff --git a/view/non_interactive_view.go b/view/non_interactive_view.go index d7a2506..3585fea 100644 --- a/view/non_interactive_view.go +++ b/view/non_interactive_view.go @@ -123,7 +123,7 @@ func getItemString(item *golang.OptimizationItem) string { totalSaving += dev.CurrentCost - dev.RightSizedCost } } - row = append(row, item.Id, item.ResourceType, item.Region, item.Platform, fmt.Sprintf("$%s", utils.FormatFloat(totalSaving))) + row = append(row, item.Id, item.ResourceType, item.Region, item.Platform, fmt.Sprintf("%s", utils.FormatPriceFloat(totalSaving))) t.AppendRow(row) itemString += t.Render() itemString += "\n " + bold.Sprint("Devices") + ":" @@ -197,7 +197,7 @@ func getDeviceString(dev *golang.Device) string { t.AppendHeader(headers) var row table.Row var itemString string - row = append(row, "└─ "+dev.DeviceId, dev.ResourceType, dev.Runtime, dev.CurrentCost, dev.RightSizedCost, fmt.Sprintf("$%s", utils.FormatFloat(dev.CurrentCost-dev.RightSizedCost))) + row = append(row, "└─ "+dev.DeviceId, dev.ResourceType, dev.Runtime, dev.CurrentCost, dev.RightSizedCost, fmt.Sprintf("%s", utils.FormatPriceFloat(dev.CurrentCost-dev.RightSizedCost))) t.AppendRow(row) itemString += t.Render() itemString += "\n " + bold.Sprint("Properties") + ":\n" + getPropertiesString(dev.Properties) @@ -425,8 +425,8 @@ func exportCsv(items []*golang.OptimizationItem) ([]string, [][]string) { for _, d := range i.Devices { for _, p := range d.Properties { rows = append(rows, []string{ - i.Id, i.ResourceType, i.Region, i.Platform, fmt.Sprintf("$%s", utils.FormatFloat(totalSaving)), - 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)), + i.Id, i.ResourceType, i.Region, i.Platform, fmt.Sprintf("%s", utils.FormatPriceFloat(totalSaving)), + 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)), p.Key, p.Current, p.Average, p.Max, p.Recommended, }) } diff --git a/view/page_overview.go b/view/page_overview.go index 050759a..523cb37 100644 --- a/view/page_overview.go +++ b/view/page_overview.go @@ -91,7 +91,7 @@ func (m OverviewPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { i.ResourceType, i.Region, i.Platform, - fmt.Sprintf("$%s (%.2f%%)", utils.FormatFloat(totalSaving), (totalSaving/totalCurrentCost)*100), + fmt.Sprintf("%s (%.2f%%)", utils.FormatPriceFloat(totalSaving), (totalSaving/totalCurrentCost)*100), } if i.Skipped { row[5] = "skipped" @@ -210,7 +210,7 @@ func (m OverviewPage) View() string { } return fmt.Sprintf("Current runtime cost: %s, Savings: %s\n%s\n%s", - style.CostStyle.Render(fmt.Sprintf("$%s", utils.FormatFloat(totalCost))), style.SavingStyle.Render(fmt.Sprintf("$%s", utils.FormatFloat(savings))), + style.CostStyle.Render(fmt.Sprintf("%s", utils.FormatPriceFloat(totalCost))), style.SavingStyle.Render(fmt.Sprintf("%s", utils.FormatPriceFloat(savings))), m.table.View(), m.statusBar.View(), ) diff --git a/view/page_resource_details.go b/view/page_resource_details.go index 9566142..11d0288 100644 --- a/view/page_resource_details.go +++ b/view/page_resource_details.go @@ -118,12 +118,12 @@ func (m ResourceDetailsPage) OnOpen() Page { item.Name, dev.ResourceType, dev.Runtime, - fmt.Sprintf("$%s", utils.FormatFloat(dev.CurrentCost)), + fmt.Sprintf("%s", utils.FormatPriceFloat(dev.CurrentCost)), ifRecommendationExists(func() string { - return fmt.Sprintf("$%s", utils.FormatFloat(dev.RightSizedCost)) + return fmt.Sprintf("%s", utils.FormatPriceFloat(dev.RightSizedCost)) }), ifRecommendationExists(func() string { - return fmt.Sprintf("$%s", utils.FormatFloat(dev.CurrentCost-dev.RightSizedCost)) + return fmt.Sprintf("%s", utils.FormatPriceFloat(dev.CurrentCost-dev.RightSizedCost)) }), }) }