BSON::Decimal128 - BSON type wrapper for Decimal128
| Use Case | Command | Description |
|---|---|---|
| π’ Create from string | bson_decimal128("123.45") | Create a Decimal128 object from a numeric string |
| π¦ Create from BID bytes | BSON::Decimal128->new(bytes => $bid) | Create from a 16βbyte BID binary representation |
| π€ Get string value | $d->value | Returns the decimal as a normalised string |
| πΎ Get BID bytes | $d->bytes | Returns the underlying 16βbyte binary data |
| π§ JSON serialisation | $d->TO_JSON | Returns string or extended JSON with $numberDecimal |
version v1.12.2
use BSON::Types ':all';
# string representation
$decimal = bson_decimal128( "1.23456789E+1000" );
# binary representation in BID format
$decimal = BSON::Decimal128->new( bytes => $bid )
π¦ This module provides a BSON type wrapper for Decimal128 values.
π’ It may be initialised with either a numeric value in string form, or with a binary Decimal128 representation (16 bytes), but not both.
β οΈ Initialisation from a string will throw an error if the string cannot be parsed as a Decimal128 or if the resulting number would not fit into 128 bits. If required, clamping or exact rounding will be applied to try to fit the value into 128 bits.
π The Decimal128 value represented as string. If not provided, it will be generated from the bytes attribute on demand.
π The Decimal128 value represented in Binary Integer Decimal (BID) format. If not provided, it will be generated from the value attribute on demand.
π€ Returns the value as a string.
π§ If the BSON_EXTJSON option is true, it will instead be compatible with MongoDBβs extended JSON (extended JSON) format, which represents it as a document as follows:
{"$numberDecimal" : "2.23372036854775807E+57"}
β‘ The stringification operator ("") is overloaded to return a (normalised) string representation. Fallback overloading is enabled.
π This software is Copyright (c) 2020 by Stefan G. and MongoDB, Inc.
π This is free software, licensed under:
The Apache License, Version 2.0, January 2004
Generated by phpman v4.9.25-4-g0d844aa · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-07 09:11 @216.73.217.93
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-pro / taotoken.net / www.chedong.com - original format