<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>The MongoDB\BSON\Decimal128 class</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongodb-bson-binary.unserialize.html">MongoDB\BSON\Binary::unserialize</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongodb-bson-decimal128.construct.html">MongoDB\BSON\Decimal128::__construct</a></div> <div class="up"><a href="book.bson.html">MongoDB\BSON</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="class.mongodb-bson-decimal128" class="reference"> <h1 class="title">The MongoDB\BSON\Decimal128 class</h1> <div class="partintro"><p class="verinfo">(mongodb >=1.2.0)</p> <div class="section" id="mongodb-bson-decimal128.intro"> <h2 class="title">Introduction</h2> <p class="para"> BSON type for the <a href="https://en.wikipedia.org/wiki/Decimal128_floating-point_format" class="link external">» Decimal128 floating-point format</a>, which supports numbers with up to 34 decimal digits (i.e. significant digits) and an exponent range of −6143 to +6144. </p> <p class="para"> Unlike the double BSON type (i.e. <span class="type"><a href="language.types.float.html" class="type float">float</a></span> in PHP), which only stores an approximation of the decimal values, the decimal data type stores the exact value. For example, <em>MongoDB\BSON\Decimal128('9.99')</em> has a precise value of 9.99 where as a double 9.99 would have an approximate value of 9.9900000000000002131628…. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> <strong class="classname">MongoDB\BSON\Decimal128</strong> is only compatible with MongoDB 3.4+. Attempting to use the BSON type with an earlier version of MongoDB will result in an error. </span> </p></blockquote> </div> <div class="section" id="mongodb-bson-decimal128.synopsis"> <h2 class="title">Class synopsis</h2> <div class="classsynopsis"> <div class="ooclass"></div> <div class="classsynopsisinfo"> <span class="modifier">final</span> <span class="ooclass"> <strong class="classname">MongoDB\BSON\Decimal128</strong> </span> <span class="oointerface">implements <span class="interfacename"><a href="class.mongodb-bson-decimal128interface.html" class="interfacename">MongoDB\BSON\Decimal128Interface</a></span> </span> <span class="oointerface">, <span class="interfacename"><a href="class.mongodb-bson-type.html" class="interfacename">MongoDB\BSON\Type</a></span> </span> <span class="oointerface">, <span class="interfacename"><a href="class.serializable.html" class="interfacename">Serializable</a></span> </span> <span class="oointerface">, <span class="interfacename"><a href="class.jsonserializable.html" class="interfacename">JsonSerializable</a></span> </span> {</div> <div class="classsynopsisinfo classsynopsisinfo_comment">/* Methods */</div> <div class="methodsynopsis dc-description"> <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-decimal128.construct.html" class="methodname">__construct</a></span> ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$value</code></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">final</span> <span class="modifier">public</span> <span class="type">mixed</span> <span class="methodname"><a href="mongodb-bson-decimal128.jsonserialize.html" class="methodname">jsonSerialize</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">final</span> <span class="modifier">public</span> <span class="type">string</span> <span class="methodname"><a href="mongodb-bson-decimal128.serialize.html" class="methodname">serialize</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">final</span> <span class="modifier">public</span> <span class="type">string</span> <span class="methodname"><a href="mongodb-bson-decimal128.tostring.html" class="methodname">__toString</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">final</span> <span class="modifier">public</span> <span class="type">void</span> <span class="methodname"><a href="mongodb-bson-decimal128.unserialize.html" class="methodname">unserialize</a></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$serialized</code></span> )</div> }</div> </div> <div class="section"> <h2 class="title">Changelog</h2> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>1.2.0</td> <td> Implements <span class="interfacename"><a href="class.serializable.html" class="interfacename">Serializable</a></span> and <span class="interfacename"><a href="class.jsonserializable.html" class="interfacename">JsonSerializable</a></span>. </td> </tr> </tbody> </table> </p> </div> </div> <h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="mongodb-bson-decimal128.construct.html">MongoDB\BSON\Decimal128::__construct</a> — Construct a new Decimal128</li><li><a href="mongodb-bson-decimal128.jsonserialize.html">MongoDB\BSON\Decimal128::jsonSerialize</a> — Returns a representation that can be converted to JSON</li><li><a href="mongodb-bson-decimal128.serialize.html">MongoDB\BSON\Decimal128::serialize</a> — Serialize a Decimal128</li><li><a href="mongodb-bson-decimal128.tostring.html">MongoDB\BSON\Decimal128::__toString</a> — Returns the string representation of this Decimal128</li><li><a href="mongodb-bson-decimal128.unserialize.html">MongoDB\BSON\Decimal128::unserialize</a> — Unserialize a Decimal128</li></ul> </div> <hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongodb-bson-binary.unserialize.html">MongoDB\BSON\Binary::unserialize</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongodb-bson-decimal128.construct.html">MongoDB\BSON\Decimal128::__construct</a></div> <div class="up"><a href="book.bson.html">MongoDB\BSON</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>