Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Capacity int64
- const (
- J Capacity = 1
- KJ = J * 1000
- MJ = KJ * 1000
- GJ = MJ * 1000
- )
- func (e Capacity) ByStack(stack basic.Stack) Capacity {
- return Capacity(e.Int64() * stack.Int64())
- }
- func (e Capacity) Int64() int64 {
- return int64(e)
- }
- func (e Capacity) String() string {
- if e == 0 {
- return "0 J"
- } else {
- switch {
- case e%GJ == 0:
- return fmt.Sprintf("%d GJ", e/GJ)
- case e%MJ == 0:
- return fmt.Sprintf("%d MJ", e/MJ)
- case e%KJ == 0:
- return fmt.Sprintf("%d KJ", e/KJ)
- default:
- return fmt.Sprintf("%d J", e)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement