Blame view

int_util.go 1.12 KB
18fcd6d6b   Marko Tikvić   merged with util ...
1
  package webutility
cacf57bd4   Marko Tikvić   merging with /uti...
2
3
4
  
  import (
  	"fmt"
cacf57bd4   Marko Tikvić   merging with /uti...
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  )
  
  // ClampInt64 ...
  func ClampInt64(v, min, max int64) int64 {
  	if v < min {
  		return min
  	} else if v > max {
  		return max
  	}
  
  	return v
  }
  
  // InRangeInt64 ...
  func InRangeInt64(v, min, max int64) bool {
  	return (v >= min && v <= max)
  }
cacf57bd4   Marko Tikvić   merging with /uti...
22
23
24
25
  // Int64ToString ...
  func Int64ToString(i int64) string {
  	return fmt.Sprintf("%d", i)
  }
1b51eed04   Marko Tikvić   pdf helper
26
27
28
29
30
31
32
  // Int64PtrToString ...
  func Int64PtrToString(i *int64) string {
  	if i == nil {
  		return ""
  	}
  	return fmt.Sprintf("%d", *i)
  }
cacf57bd4   Marko Tikvić   merging with /uti...
33
34
35
36
37
38
39
40
41
42
43
44
  // BoolToInt64 ...
  func BoolToInt64(b bool) int64 {
  	if b {
  		return 1
  	}
  	return 0
  }
  
  // Int64ToBool ...
  func Int64ToBool(i int64) bool {
  	return i != 0
  }
b3f624151   Marko Tikvić   StringToValidInt64()
45

b80ee4b2b   Marko Tikvić   new stuff
46
  func MaxInt(vars ...int) (max int) {
1b51eed04   Marko Tikvić   pdf helper
47
  	max = vars[0]
b80ee4b2b   Marko Tikvić   new stuff
48
49
50
51
  	for _, v := range vars {
  		if v > max {
  			max = v
  		}
b3f624151   Marko Tikvić   StringToValidInt64()
52
  	}
b80ee4b2b   Marko Tikvić   new stuff
53
  	return max
b3f624151   Marko Tikvić   StringToValidInt64()
54
  }
1b51eed04   Marko Tikvić   pdf helper
55
56
57
58
59
60
61
62
63
64
  
  func MinInt64(vars ...int64) (min int64) {
  	min = vars[0]
  	for _, v := range vars {
  		if v < min {
  			min = v
  		}
  	}
  	return min
  }
bf3ea2f8e   Marko Tikvić   format number
65
66
67
68
69
70
71
  
  func FormatInt64Number(i int64) string {
  	res := ""
  
  	for i >= 1000 {
  		rem := i % 1000
  		i = i / 1000
2c237577d   Marko Tikvić   fixed int formati...
72
73
  		//res = res + fmt.Sprintf(".%03d", rem)
  		res = fmt.Sprintf(".%03d", rem) + res
bf3ea2f8e   Marko Tikvić   format number
74
75
76
77
  	}
  	res = fmt.Sprintf("%d", i) + res
  	return res
  }