MCPcopy
hub / github.com/shopspring/decimal / NewFromFloat

Function NewFromFloat

decimal.go:299–304  ·  view source on GitHub ↗

NewFromFloat converts a float64 to Decimal. The converted number will contain the number of significant digits that can be represented in a float with reliable roundtrip. This is typically 15 digits, but may be more in some cases. See https://www.exploringbinary.com/decimal-precision-of-binary-floa

(value float64)

Source from the content-addressed store, hash-verified

297//
298// NOTE: this will panic on NaN, +/-inf
299func NewFromFloat(value float64) Decimal {
300 if value == 0 {
301 return New(0, 0)
302 }
303 return newFromFloat(value, math.Float64bits(value), &float64info)
304}
305
306// NewFromFloat32 converts a float32 to Decimal.
307//

Callers 15

BenchmarkNewFromFloatFunction · 0.85
TestNewFromFloatFunction · 0.85
TestNewFromFloatRandomFunction · 0.85
TestNewFromFloatQuickFunction · 0.85
TestDecimal_MinFunction · 0.85
TestDecimal_MaxFunction · 0.85
TestDecimal_ScanFunction · 0.85

Calls 2

NewFunction · 0.85
newFromFloatFunction · 0.85

Tested by 15

BenchmarkNewFromFloatFunction · 0.68
TestNewFromFloatFunction · 0.68
TestNewFromFloatRandomFunction · 0.68
TestNewFromFloatQuickFunction · 0.68
TestDecimal_MinFunction · 0.68
TestDecimal_MaxFunction · 0.68
TestDecimal_ScanFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…