Files
go_goutils/tplx/sprigx/funcs_tpl_nums.go
brent saner 67c7faf449 v1.16.6
FIXED:
* tplx/sprigx float to string non-truncating was... truncating. it no
  longer is.
2026-01-30 20:21:34 -05:00

52 lines
998 B
Go

package sprigx
import (
`math/big`
)
// numFloat64 returns any string representation of a numeric value or any type of numeric value to a float64.
func numFloat64(val any) (f float64, err error) {
if f, _, err = toFloat64(val); err != nil {
return
}
return
}
/*
numFloatStr wraps numFloat32Str and numFloat64Str.
val can be a string representation of any numeric value or any type of numeric value.
*/
func numFloatStr(val any) (s string, err error) {
var f float64
if f, _, err = toFloat64(val); err != nil {
return
}
s = numFloat64Str(f)
return
}
// numFloat32Str returns float32 f as a complete string representation with no truncation (or right-padding).
func numFloat32Str(f float32) (s string) {
s = numFloat64Str(float64(f))
return
}
// numFloat64Str returns float64 f as a complete string representation with no truncation (or right-padding).
func numFloat64Str(f float64) (s string) {
var bf *big.Float
bf = big.NewFloat(f)
s = bf.Text('f', -1)
return
}