百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

money

> 编程语言
开源

表示货币价值的值对象(使用货币的最小单位)。

728 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

表示货币价值的值对象(使用货币的最小单位)。

**此项目已被放弃。**它最初只是用作 PHPUnit 功能等的示例,并不适用于生产环境。我很抱歉没有明确说明这一点。请转而查看 moneyphp/money。

{ "require": { "sebastian/money": "^1.6" } }

使用示例

创建 Money 对象并访问其货币值

php
use SebastianBergmann\Money\Currency;
use SebastianBergmann\Money\Money;

// Create Money object that represents 1 EUR
$m = new Money(100, new Currency('EUR'));

// Access the Money object's monetary value
print $m->getAmount();

// Access the Money object's monetary value converted to its base units
print $m->getConvertedAmount();

上述代码生成了下面所示的输出: 1.00

从字符串值创建 Money 对象

php
use SebastianBergmann\Money\Currency;
use SebastianBergmann\Money\Money;

// Create Money object that represents 12.34 EUR
$m = Money::fromString('12.34', new Currency('EUR'))

// Access the Money object's monetary value
print $m->getAmount();

上述代码生成了下面所示的输出:

使用货币特定的 Money 子类

php
use SebastianBergmann\Money\EUR;

// Create Money object that represents 1 EUR
$m = new EUR(100);

// Access the Money object's monetary value
print $m->getAmount();

上述代码生成了下面所示的输出: 请注意,没有 Money 的子类专用于土耳其里拉,因为 TRY 在 PHP 中不是有效的类名。

使用 PHP 内置的 NumberFormatter 格式化 Money 对象

php 使用塞巴斯蒂安

100 1234 100

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言