mirror of
https://github.com/retailcrm/mg-transport-core.git
synced 2024-11-22 05:06:04 +03:00
Add a function to format currency value
This commit is contained in:
commit
cf9690e2e6
@ -263,3 +263,7 @@ func GetCurrencySymbol(code string) string {
|
||||
|
||||
return strings.ToUpper(code)
|
||||
}
|
||||
|
||||
func FormatCurrencyValue(value float32) string {
|
||||
return fmt.Sprintf("%.2f", value)
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user