1
0
mirror of https://github.com/php/doc-en.git synced 2026-03-25 16:22:20 +01:00
Files
archived-doc-en/reference/bc/bcmath/number/construct.xml
2025-01-29 17:20:48 +09:00

115 lines
3.0 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<refentry xml:id="bcmath-number.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>BcMath\Number::__construct</refname>
<refpurpose>Creates a BcMath\Number object</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<constructorsynopsis role="BcMath\\Number">
<modifier>public</modifier> <methodname>BcMath\Number::__construct</methodname>
<methodparam><type class="union"><type>string</type><type>int</type></type><parameter>num</parameter></methodparam>
</constructorsynopsis>
<simpara>
Creates a <classname>BcMath\Number</classname> object from an <type>int</type> or <type>string</type> value.
</simpara>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>num</parameter></term>
<listitem>
<simpara>
An <type>int</type> or <type>string</type> value.
If <parameter>num</parameter> is a <type>int</type>,
the <property>BcMath\Number::scale</property> is always set to <literal>0</literal>.
If <parameter>num</parameter> is a <type>string</type>, it must be a valid number,
and the <property>BcMath\Number::scale</property> is automatically set by parsing the string.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<simpara>
This method throws a <exceptionname>ValueError</exceptionname> if <parameter>num</parameter>
is <type>string</type> and not a well-formed BCMath numeric string.
</simpara>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><methodname>BcMath\Number::__construct</methodname> example</title>
<programlisting role="php">
<![CDATA[
<?php
$num1 = new BcMath\Number(100);
$num2 = new BcMath\Number('-200');
$num3 = new BcMath\Number('300.00');
var_dump($num1, $num2, $num3);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
object(BcMath\Number)#1 (2) {
["value"]=>
string(3) "100"
["scale"]=>
int(0)
}
object(BcMath\Number)#2 (2) {
["value"]=>
string(4) "-200"
["scale"]=>
int(0)
}
object(BcMath\Number)#3 (2) {
["value"]=>
string(6) "300.00"
["scale"]=>
int(2)
}
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><methodname>BcMath\Number::__serialize</methodname></member>
<member><methodname>BcMath\Number::__unserialize</methodname></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->