v1.16.4
ADDED: * math, time functions to tplx/sprigx FIXED: * logging not initializing properly on some BSDs
This commit is contained in:
51
tplx/sprigx/funcs_tpl_nums.go
Normal file
51
tplx/sprigx/funcs_tpl_nums.go
Normal file
@@ -0,0 +1,51 @@
|
||||
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.String()
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user