PHP 8.5.0 RC 2 available for testing

The BcMath\Number class

(PHP 8 >= 8.4.0)

็ฎ€ไป‹

A class for an arbitrary precision number. These objects support overloaded arithmetic and comparison operators.

ๆณจๆ„: This class is not affected by the bcmath.scale INI directive set in php.ini.

ๆณจๆ„: The behavior of an overloaded operator is the same as specifying null for the scale parameter on the corresponding method.

็ฑปๆ‘˜่ฆ

final readonly class BcMath\Number implements Stringable {
/* ๅฑžๆ€ง */
public string $value;
public int $scale;
/* ๆ–นๆณ• */
public __construct(string|int $num)
public compare(BcMath\Number|string|int $num, ?int $scale = null): int
public divmod(BcMath\Number|string|int $num, ?int $scale = null): array
public pow(BcMath\Number|string|int $exponent, ?int $scale = null): BcMath\Number
public powmod(BcMath\Number|string|int $exponent, BcMath\Number|string|int $modulus, ?int $scale = null): BcMath\Number
public round(int $precision = 0, RoundingMode $mode = RoundingMode::HalfAwayFromZero): BcMath\Number
public __serialize(): array
public sqrt(?int $scale = null): BcMath\Number
public __toString(): string
public __unserialize(array $data): void
}

ๅฑžๆ€ง

value
A string representation of an arbitrary precision number.
scale
The scale value currently set on the object. For objects resulting from calculations, this value is automatically computed and set, unless the scale parameter was set in the calculation method.

็›ฎๅฝ•

๏ผ‹ๆทปๅŠ ๅค‡ๆณจ

็”จๆˆท่ดก็Œฎ็š„ๅค‡ๆณจ 1 note

up
2
harl at gmail dot com ยถ
6 months ago
BcMath\Number is one of those classes that overloads boolean casting.
If $z = new BcMath\Number(0) then $z is considered falsy (and hence, for example, empty($z)==true) even though it is a genuine Number object.
To Top