MCPcopy
hub / github.com/flosch/pongo2 / Float

Method Float

value.go:161–180  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

159// value, if necessary). If it's not possible to convert the underlying value,
160// it will return 0.0.
161func (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

Callers 14

NegateMethod · 0.95
LessMethod · 0.95
StringMethod · 0.80
IntegerMethod · 0.80
IsTrueMethod · 0.80
LessMethod · 0.80
ExecuteMethod · 0.80
EvaluateMethod · 0.80
EvaluateMethod · 0.80
EvaluateMethod · 0.80
EvaluateMethod · 0.80
filterAddFunction · 0.80

Calls 3

getResolvedValueMethod · 0.95
logfFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected