package utils

import "strconv"

// ToFloat64 converts a value to float64, handling float64, float32, int, int32,
// int64, and string types. Returns (value, true) on success or (0, false) if the
// value cannot be converted.
func ToFloat64(v interface{}) (float64, bool) {
	switch val := v.(type) {
	case float64:
		return val, true
	case float32:
		return float64(val), true
	case int:
		return float64(val), true
	case int64:
		return float64(val), true
	case int32:
		return float64(val), true
	case string:
		f, err := strconv.ParseFloat(val, 64)
		if err != nil {
			return 0, false
		}
		return f, true
	default:
		return 0, false
	}
}
