Float returns the underlying value as a float (converts the underlying value, if necessary). If it's not possible to convert the underlying value, it will return 0.0.
()
| 159 | // value, if necessary). If it's not possible to convert the underlying value, |
| 160 | // it will return 0.0. |
| 161 | func (v *Value) Float() float64 { |
| 162 | switch v.getResolvedValue().Kind() { |
| 163 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
| 164 | return float64(v.getResolvedValue().Int()) |
| 165 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: |
| 166 | return float64(v.getResolvedValue().Uint()) |
| 167 | case reflect.Float32, reflect.Float64: |
| 168 | return v.getResolvedValue().Float() |
| 169 | case reflect.String: |
| 170 | // Try to convert from string to float64 (base 10) |
| 171 | f, err := strconv.ParseFloat(v.getResolvedValue().String(), 64) |
| 172 | if err != nil { |
| 173 | return 0.0 |
| 174 | } |
| 175 | return f |
| 176 | default: |
| 177 | logf("Value.Float() not available for type: %s\n", v.getResolvedValue().Kind().String()) |
| 178 | return 0.0 |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // Bool returns the underlying value as bool. If the value is not bool, false |
| 183 | // will always be returned. If you're looking for true/false-evaluation of the |