Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.70 KB | None | 0 0
  1. type Capacity int64
  2.  
  3. const (
  4.     J Capacity  = 1
  5.     KJ          = J * 1000
  6.     MJ          = KJ * 1000
  7.     GJ          = MJ * 1000
  8. )
  9.  
  10. func (e Capacity) ByStack(stack basic.Stack) Capacity {
  11.     return Capacity(e.Int64() * stack.Int64())
  12. }
  13.  
  14. func (e Capacity) Int64() int64 {
  15.     return int64(e)
  16. }
  17.  
  18. func (e Capacity) String() string {
  19.     if e == 0 {
  20.         return "0 J"
  21.     } else {
  22.         switch {
  23.         case e%GJ == 0:
  24.             return fmt.Sprintf("%d GJ", e/GJ)
  25.         case e%MJ == 0:
  26.             return fmt.Sprintf("%d MJ", e/MJ)
  27.         case e%KJ == 0:
  28.             return fmt.Sprintf("%d KJ", e/KJ)
  29.         default:
  30.             return fmt.Sprintf("%d J", e)
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement