adding percent value format
This commit is contained in:
parent
e7c2568a69
commit
1cbfb53b11
2 changed files with 11 additions and 0 deletions
|
@ -59,6 +59,8 @@ const (
|
|||
DefaultDateHourFormat = "01-02 3pm"
|
||||
// DefaultFloatFormat is the default float format.
|
||||
DefaultFloatFormat = "%.2f"
|
||||
// DefaultPercentValueFormat is the default percent format.
|
||||
DefaultPercentValueFormat = "%0.2f%%"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -37,6 +37,15 @@ func FloatValueFormatter(v interface{}) string {
|
|||
return FloatValueFormatterWithFormat(v, DefaultFloatFormat)
|
||||
}
|
||||
|
||||
// PercentValueFormatter is a formatter for percent values.
|
||||
// NOTE: it normalizes the values, i.e. multiplies by 100.0.
|
||||
func PercentValueFormatter(v interface{}) string {
|
||||
if typed, isTyped := v.(float64); isTyped {
|
||||
return FloatValueFormatterWithFormat(typed*100.0, DefaultPercentValueFormat)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// FloatValueFormatterWithFormat is a ValueFormatter for float64 with a given format.
|
||||
func FloatValueFormatterWithFormat(v interface{}, floatFormat string) string {
|
||||
if typed, isTyped := v.(float64); isTyped {
|
||||
|
|
Loading…
Reference in a new issue