MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / convertToFloat

Function convertToFloat

structure/types.go:167–193  ·  view source on GitHub ↗

convertToFloat converts an interface to a float64

(Value interface{})

Source from the content-addressed store, hash-verified

165
166// convertToFloat converts an interface to a float64
167func convertToFloat(Value interface{}) (float64, error) {
168 switch value := Value.(type) {
169 case int:
170 return float64(value), nil
171 case uint:
172 return float64(value), nil
173 case float32:
174 return float64(value), nil
175 case float64:
176 return value, nil
177 case string:
178 floatValue, err := strconv.ParseFloat(value, 64)
179 if err != nil {
180 return 0, err
181 }
182 return floatValue, nil
183 case []byte:
184 strValue := string(value)
185 floatValue, err := strconv.ParseFloat(strValue, 64)
186 if err != nil {
187 return 0, err
188 }
189 return floatValue, nil
190 default:
191 return 0, errors.New("unsupported type")
192 }
193}
194
195func convertToRegexp(pattern string) string {
196 // 转义正则特殊字符

Callers 1

IncrByFloatMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected