// Attempts to typecast the current value into a float64.
// Returns error if the current value is not a json number.
// Example:
//		percentage, err := v.Float64()
353031
func (v *Value) Float64() (float64, error) {
	n, err := v.Number()

	if err != nil {
		return 0, err
	}

	return n.Float64()
}
4704
func percentToString(f float64) string {
	fInt := int64(f * 1000)
	if fInt == 0 {
		return "0"
	}
	if fInt == 1000 {
		return "100"
	}
	if fInt < 0 || fInt > 1000 {
		return "INVALID"
	}
	r := strconv.FormatInt(fInt, 10)
	r = strings.TrimRight(r, "0")
	for len(r) < 2 {
		r = r + "0"
	}
	return r
}
1044210
func ToFloat(data interface{}) (float64, bool) {
	switch typed := data.(type) {
	case float64:
		return typed, true
	case float32:
		return float64(typed), true
	default:
		if n, ok := ToInt(data); ok {
			return float64(n), true
		}
		return 0, false
	}
}
170120
func (v *Value) ToFloat() (val float64, ok bool) {
	switch v.vType {
	case typeFloat:
		val, ok = v.value.(float64)
	case typeInt:
		var i int64
		i, ok = v.value.(int64)
		val = float64(i)
	default:
	}
	return
}
672723
func (s *Session) Float64(key string) float64 {
	s.RLock()
	defer s.RUnlock()

	v, ok := s.data[key]
	if !ok {
		return 0
	}

	value, ok := v.(float64)
	if !ok {
		return 0
	}
	return value
}
789077
func (nn NullNumber) Float64() (float64, error) {
	if nn.IsNil() {
		return 0, errors.New("NullNumber is nil")
	}
	return strconv.ParseFloat(nn.value.(string), 64)
}
286205
func ToFloat(str string) (float64, error) {
	res, err := strconv.ParseFloat(str, 64)
	if err != nil {
		res = 0.0
	}
	return res, err
}
715417
func ToFloat64(v Value) (float64, error) {
	num, err := newNumeric(v)
	if err != nil {
		return 0, err
	}
	switch num.typ {
	case Int64:
		return float64(num.ival), nil
	case Uint64:
		return float64(num.uval), nil
	case Float64:
		return num.fval, nil
	}
	panic("unreachable")
}
1046010
func (v *value) AsFloat64(dv float64) float64 {
	if v.IsUndefined() {
		return dv
	}
	switch tv := v.raw.(type) {
	case string:
		f, err := strconv.ParseFloat(tv, 64)
		if err != nil {
			return dv
		}
		return f
	case int:
		return float64(tv)
	case float64:
		return tv
	case bool:
		if tv {
			return 1.0
		}
		return 0.0
	}
	return dv
}
355088
func (f *Forms) Float64(key string) (float64, error) {
	return strconv.ParseFloat((*http.Request)(f).FormValue(key), 64)
}
456790
func (r *Reply) Float64() (float64, error) {
	if r.Type == ErrorReply {
		return 0, r.Err
	}
	if r.Type == BulkReply {
		s, err := r.Str()
		if err != nil {
			return 0, err
		}
		f64, err := strconv.ParseFloat(s, 64)
		if err != nil {
			return 0, errors.New("failed to parse float value from string value")
		} else {
			return f64, nil
		}
	}

	return 0, errors.New("float value is not available for this reply type")
}
572252
func toFloat64(v reflect.Value) float64 {
	f, _ := tryToFloat64(v)
	return f
}
156497
func Float64(short string, long string, value float64, usage string) *float64 {
	flagVar := value
	return Float64Var(&flagVar, short, long, value, usage)
}
414972
func NumberToFloat(n ast.Number) *big.Float {
	r, ok := new(big.Float).SetString(string(n))
	if !ok {
		panic("illegal value")
	}
	return r
}
1245655
func ConvertFloatToInt(fval float64, lowerBound, upperBound int64, tp byte) (int64, error) {
	val := RoundFloat(fval)
	if val < float64(lowerBound) {
		return lowerBound, overflow(val, tp)
	}

	if val >= float64(upperBound) {
		if val == float64(upperBound) {
			return upperBound, nil
		}
		return upperBound, overflow(val, tp)
	}
	return int64(val), nil
}
1107552
func Float(v float64) *float64 {
	p := new(float64)
	*p = v
	return p
}
773046
func ValueToInt64(val Value) (int64, bool) {
	if val == nil || val.Nil() || val.Err() {
		return 0, false
	}
	switch v := val.(type) {
	case NumericValue:
		return v.Int(), true
	case StringValue:
		return convertStringToInt64(0, v.Val())
	case Slice:
		if v.Len() > 0 {
			return ValueToInt64(v.SliceValue()[0])
		}
	}
	return 0, false
}