Int returns an integer representation.
()
| 123 | |
| 124 | // Int returns an integer representation. |
| 125 | func (t Result) Int() int64 { |
| 126 | switch t.Type { |
| 127 | default: |
| 128 | return 0 |
| 129 | case True: |
| 130 | return 1 |
| 131 | case String: |
| 132 | n, _ := parseInt(t.Str) |
| 133 | return n |
| 134 | case Number: |
| 135 | // try to directly convert the float64 to int64 |
| 136 | i, ok := safeInt(t.Num) |
| 137 | if ok { |
| 138 | return i |
| 139 | } |
| 140 | // now try to parse the raw string |
| 141 | i, ok = parseInt(t.Raw) |
| 142 | if ok { |
| 143 | return i |
| 144 | } |
| 145 | // fallback to a standard conversion |
| 146 | return int64(t.Num) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // Uint returns an unsigned integer representation. |
| 151 | func (t Result) Uint() uint64 { |