-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpercent.go
63 lines (62 loc) · 1.23 KB
/
percent.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package domain
//import (
// "fmt"
// "strconv"
//)
//
//type Percent float64
//
//func NewPercent(p float64) Percent {
// return Percent(round(p, 6))
//}
//
//func ParsePercent(s string) (Percent, error) {
// var p Percent
//
// return p, p.UnmarshalJSON([]byte(fmt.Sprintf(`"%s"`, s)))
//}
//
//func (p Percent) Between(from, to Percent) bool {
// return !(p > to || p < from)
//}
//
//func (p Percent) Normalize() float64 {
// return float64(p) / 100
//}
//
////func (p Percent) Of(c Money) Money {
//// return c.Multi(float64(p / 100))
////}
//
//func (p Percent) String() string {
// return fmt.Sprintf("%.2f%%", p)
//}
//
//func (p Percent) MarshalJSON() ([]byte, error) {
// return []byte(fmt.Sprintf(`"%s"`, strconv.FormatFloat(float64(p), 'f', -1, 64))), nil
//}
//
//func (p *Percent) UnmarshalJSON(b []byte) error {
// n := len(b)
// if n <= 2 {
// return nil
// }
//
// f, err := strconv.ParseFloat(string(b[1:n-1]), 32)
// if err != nil {
// return err
// }
//
// *p = NewPercent(f)
// return nil
//}
//
//type Tax struct{ Percent }
//
//func NewTax(percent float64) (Tax, error) {
// p := NewPercent(percent)
// if !p.Between(0, 100) {
// return Tax{p}, Errorf("tax: expected 0%% - 100%%, got %s", p.String())
// }
// return Tax{p}, nil
//}