Skip to content

Commit 3376842

Browse files
committed
Add AsFloat functions to handle raw values
1 parent 476bc7b commit 3376842

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

bson/raw_value.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,14 @@ func (rv RawValue) AsInt64() int64 { return convertToCoreValue(rv).AsInt64() }
294294
// panicking.
295295
func (rv RawValue) AsInt64OK() (int64, bool) { return convertToCoreValue(rv).AsInt64OK() }
296296

297+
// AsFloat64 returns a BSON number as a float64. If the BSON type is not a numeric one, this method
298+
// will panic.
299+
func (rv RawValue) AsFloat64() float64 { return convertToCoreValue(rv).AsFloat64() }
300+
301+
// AsFloat64OK is the same as AsFloat64, except that it returns a boolean instead of
302+
// panicking.
303+
func (rv RawValue) AsFloat64OK() (float64, bool) { return convertToCoreValue(rv).AsFloat64OK() }
304+
297305
// Decimal128 returns the decimal the Value represents. It panics if the value is a BSON type other than
298306
// decimal.
299307
func (rv RawValue) Decimal128() Decimal128 { return NewDecimal128(convertToCoreValue(rv).Decimal128()) }

0 commit comments

Comments
 (0)