MCPcopy Create free account
hub / github.com/OverloadBlitz/cloudcent-cli / formatDecimal

Function formatDecimal

internal/estimate/print.go:889–903  ·  view source on GitHub ↗

formatDecimal formats a decimal.Decimal for display, trimming trailing zeros but keeping at least `minDecimals` decimal places.

(d decimal.Decimal, minDecimals int32)

Source from the content-addressed store, hash-verified

887// formatDecimal formats a decimal.Decimal for display, trimming trailing zeros
888// but keeping at least `minDecimals` decimal places.
889func formatDecimal(d decimal.Decimal, minDecimals int32) string {
890 // Use enough precision to show meaningful digits, then trim trailing zeros.
891 s := d.StringFixed(minDecimals)
892 // Trim trailing zeros after decimal point, but keep at least 2 decimal places.
893 if strings.Contains(s, ".") {
894 s = strings.TrimRight(s, "0")
895 // Ensure at least 2 decimal places for currency readability.
896 if idx := strings.Index(s, "."); idx >= 0 && len(s)-idx-1 < 2 {
897 for len(s)-strings.Index(s, ".")-1 < 2 {
898 s += "0"
899 }
900 }
901 }
902 return "$" + s
903}
904
905func indent(s, prefix string) string {
906 out := ""

Callers 1

renderTotalsTableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected