pronamic/wp-number
Composer 安装命令:
composer require pronamic/wp-number
包简介
WordPress Number library.
README 文档
README
WordPress Number library.
Table of contents
Getting Started
Installation
composer require pronamic/wp-number
Usage
$number = Number::from_float( 123.50 )->add( 0.45 );
echo \esc_html( $number->format_i18n( 2 ) );
Design Principles
A number is a number
In general, a number is a number, not a string, and this means that any programming language treats a number as a number. Thus, the number by itself doesn't imply any specific format (like using .000021 instead of 2.1e-5). This is nothing different to displaying a number with leading zeros (like 0.000021) or aligning lists of numbers. This is a general issue you'll find in any programming language: if you want a specific format you need to specify it, using the format functions of your programming language.
Unless you specify the number as string and convert it to a real number when needed, of course. Some languages can do this implicitly.
https://stackoverflow.com/a/1471792
Number in exponential form / scientific notation
2.1E-5 is the same number as 0.000021. That's how it prints numbers below 0.001. Use printf() if you want it in a particular format.
Edit If you're not familiar with the
2.1E-5syntax, you should know it is shorthand for 2.1×10-5. It is how most programming languages represent numbers in scientific notation.
https://stackoverflow.com/a/1471694
Leading zeros
In https://github.com/moneyphp/money it is not allowed to use leading zeros:
Leading zeros are not allowed
Source: https://github.com/moneyphp/money/search?q=leading+zero
This probably has somehting to do with the following user note:
Be careful with GMP - it considers leading zeros in a number string as meaning the number is in octal, whereas 'bc' doesn't:
gmp_strval("000100", 10) => 64
bcmul("000100", "1") => 100
Source: https://www.php.net/manual/en/book.gmp.php#106521
<?php $a = 1234; // decimal number $a = 0123; // octal number (equivalent to 83 decimal) $a = 0x1A; // hexadecimal number (equivalent to 26 decimal) $a = 0b11111111; // binary number (equivalent to 255 decimal) $a = 1_234_567; // decimal number (as of PHP 7.4.0) ?>
Source: https://www.php.net/manual/en/language.types.integer.php
A leading zero in a numeric literal means "this is octal". But don't be confused: a leading zero in a string does not. Thus:
$x = 0123; // 83$y = "0123" + 0 // 123
Source: https://www.php.net/manual/en/language.types.integer.php#111523
Links
pronamic/wp-number 适用场景与选型建议
pronamic/wp-number 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 95.38k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 03 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「i18n」 「wordpress」 「number」 「calculator」 「Double」 「int」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pronamic/wp-number 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pronamic/wp-number 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pronamic/wp-number 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use i18n translation PHP class for multi-language websites
A custom URL rule class for Yii 2 which allows to create translated URL rules
A package for working with arbitrary precision numbers in Laravel.
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Nette Framework adapter for I18n package
Gambling Algorithms for Certification.
统计信息
- 总下载量: 95.38k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 15
- 依赖项目数: 15
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2021-03-09
