(a interface{}, p int, rOpt ...float64)
| 105 | } |
| 106 | |
| 107 | func round(a interface{}, p int, rOpt ...float64) float64 { |
| 108 | roundOn := .5 |
| 109 | if len(rOpt) > 0 { |
| 110 | roundOn = rOpt[0] |
| 111 | } |
| 112 | val := toFloat64(a) |
| 113 | places := toFloat64(p) |
| 114 | |
| 115 | var round float64 |
| 116 | pow := math.Pow(10, places) |
| 117 | digit := pow * val |
| 118 | _, div := math.Modf(digit) |
| 119 | if div >= roundOn { |
| 120 | round = math.Ceil(digit) |
| 121 | } else { |
| 122 | round = math.Floor(digit) |
| 123 | } |
| 124 | return round / pow |
| 125 | } |
| 126 | |
| 127 | // converts unix octal to decimal |
| 128 | func toDecimal(v interface{}) int64 { |