Add a function to format currency value

This commit is contained in:
Andrey Muriy 2021-09-29 10:27:36 +03:00
parent 50a8ad5f19
commit 51cbd9898d
2 changed files with 12 additions and 0 deletions

View File

@ -263,3 +263,7 @@ func GetCurrencySymbol(code string) string {
return strings.ToUpper(code) return strings.ToUpper(code)
} }
func FormatCurrencyValue(value float32) string {
return fmt.Sprintf("%.2f", value)
}

View File

@ -261,6 +261,14 @@ func TestUtils_ReplaceMarkdownSymbols(t *testing.T) {
assert.Equal(t, expected, ReplaceMarkdownSymbols(test)) 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) { func TestUtils_Suite(t *testing.T) {
suite.Run(t, new(UtilsTest)) suite.Run(t, new(UtilsTest))
} }