-
Notifications
You must be signed in to change notification settings - Fork 5
/
float_formatter.go
42 lines (35 loc) · 915 Bytes
/
float_formatter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package format
import (
"fmt"
"strings"
)
// f32Formatter ...
type f32Formatter struct {
value float32
}
// Clarify formatter implementation
func (f f32Formatter) Clarify(a string) (Formatter, error) {
if len(strings.TrimSpace(a)) != 0 {
return f, fmt.Errorf("No clarification available for float32 formatter")
}
return f, nil
}
// Format formatter implementation
func (f f32Formatter) Format(a string) (string, error) {
return fmt.Sprintf("%"+a+"f", f.value), nil
}
// f64Formatter ...
type f64Formatter struct {
value float64
}
// Clarify formatter implementation
func (f f64Formatter) Clarify(a string) (Formatter, error) {
if len(strings.TrimSpace(a)) != 0 {
return f, fmt.Errorf("No clarification available for float64 formatter")
}
return f, nil
}
// Format formatter implementation
func (f f64Formatter) Format(a string) (string, error) {
return fmt.Sprintf("%"+a+"f", f.value), nil
}