Add a function to format currency value

This commit is contained in:
Alex Lushpai 2021-09-29 11:32:45 +03:00 committed by GitHub
commit cf9690e2e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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))
} }