diff --git a/core/utils.go b/core/utils.go index f7430e9..50ec066 100644 --- a/core/utils.go +++ b/core/utils.go @@ -263,3 +263,7 @@ func GetCurrencySymbol(code string) string { return strings.ToUpper(code) } + +func FormatCurrencyValue(value float32) string { + return fmt.Sprintf("%.2f", value) +} diff --git a/core/utils_test.go b/core/utils_test.go index 1750188..0e1ebb7 100644 --- a/core/utils_test.go +++ b/core/utils_test.go @@ -261,6 +261,14 @@ func TestUtils_ReplaceMarkdownSymbols(t *testing.T) { assert.Equal(t, expected, ReplaceMarkdownSymbols(test)) } +func TestUtils_FormatCurrencyValue(t *testing.T) { + assert.Equal(t, "-1.00", FormatCurrencyValue(-1)) + assert.Equal(t, "100.00", FormatCurrencyValue(100)) + assert.Equal(t, "111.11", FormatCurrencyValue(111.11)) + assert.Equal(t, "123.46", FormatCurrencyValue(123.456789)) + assert.Equal(t, "1000500.00", FormatCurrencyValue(1000500)) +} + func TestUtils_Suite(t *testing.T) { suite.Run(t, new(UtilsTest)) }