Commit e9419e37db0c162061220eea2867a17550ce5ca8

Authored by Marko Tikvić
1 parent e95e683624
Exists in master

string to float

Showing 1 changed file with 6 additions and 0 deletions   Show diff stats
1 package webutility 1 package webutility
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "strconv" 5 "strconv"
6 ) 6 )
7 7
8 // ClampInt64 ... 8 // ClampInt64 ...
9 func ClampInt64(v, min, max int64) int64 { 9 func ClampInt64(v, min, max int64) int64 {
10 if v < min { 10 if v < min {
11 return min 11 return min
12 } else if v > max { 12 } else if v > max {
13 return max 13 return max
14 } 14 }
15 15
16 return v 16 return v
17 } 17 }
18 18
19 // InRangeInt64 ... 19 // InRangeInt64 ...
20 func InRangeInt64(v, min, max int64) bool { 20 func InRangeInt64(v, min, max int64) bool {
21 return (v >= min && v <= max) 21 return (v >= min && v <= max)
22 } 22 }
23 23
24 // StringToInt64 ... 24 // StringToInt64 ...
25 func StringToInt64(s string) int64 { 25 func StringToInt64(s string) int64 {
26 i, _ := strconv.ParseInt(s, 10, 64) 26 i, _ := strconv.ParseInt(s, 10, 64)
27 return i 27 return i
28 } 28 }
29 29
30 // StringToFloat64 ...
31 func StringToFloat64(s string) float64 {
32 f, _ := strconv.ParseFloat(s, 64)
33 return f
34 }
35
30 // Int64ToString ... 36 // Int64ToString ...
31 func Int64ToString(i int64) string { 37 func Int64ToString(i int64) string {
32 return fmt.Sprintf("%d", i) 38 return fmt.Sprintf("%d", i)
33 } 39 }
34 40
35 // BoolToInt64 ... 41 // BoolToInt64 ...
36 func BoolToInt64(b bool) int64 { 42 func BoolToInt64(b bool) int64 {
37 if b { 43 if b {
38 return 1 44 return 1
39 } 45 }
40 return 0 46 return 0
41 } 47 }
42 48
43 // Int64ToBool ... 49 // Int64ToBool ...
44 func Int64ToBool(i int64) bool { 50 func Int64ToBool(i int64) bool {
45 return i != 0 51 return i != 0
46 } 52 }
47 53