nickjbedford/decimal

一个封装 BC 库的 Decimal 类的定制实现。

1.1.0 2024-06-27 23:45 UTC

This package is auto-updated.

Last update: 2024-09-28 00:15:54 UTC


README

此库将 BC Math 库实现为名为 ImmutableDecimal(不可变)和 Decimal(可变)的类对。这些类提供了常见的操作,如简单算术、相等性和比较方法,以及格式化和小数精度更改。

示例用法

不可变十进制算术

$balance = new \YetAnother\ImmutableDecimal(144.52, 2);
$newBalance = $balance->plus(55.95);
$newBalance->printValue(); // "200.02"

if ($newBalance->greaterThanOrEqual(200)) {
    print("New balance is at or over $200.");
}

可变十进制算术(带辅助工具)

$amount = d4('129.9523'); // 4-digit precision (mutable) Decimal
$amount->add(87.5); // addition in place
$amount->printValue(); // "217.4523"

$remainder = $amount->modulus(5.5);
$remainder->printValue(); // "2.9523"