laravel-ready/readable-numbers
Composer 安装命令:
composer require laravel-ready/readable-numbers
包简介
Human readable numbers for Laravel
README 文档
README
Human readable numbers for Laravel. In some cases, you may need to format numbers in a way that is easier to read. Especially when you are dealing with numbers that are very large, for example we want to show page views and we have 100000000 views. So we can show it in the 100M format.
Installation
composer require laravel-ready/readable-numbers
Thresholds
| Threshold | Suffix | Result |
|---|---|---|
| 900 | 900 | |
| 900.000 | k | 0.9 K |
| 900.000.000 | m | 0.9 M |
| 900.000.000.000 | b | 9 T |
| 90.000.000.000.000 | t | 900 T |
Usages
make method takes 3 aguments: make(float $value, int $decimals = 1, $lang = null)
Service Example
use LaravelReady\ReadableNumbers\Services\ReadableNumbers; ... $readableNumber = ReadableNumbers::make(123456789); // 123.5 M $readableNumber = ReadableNumbers::make(-123456789); // -123.5 M // with more decimals $readableNumber = ReadableNumbers::make(123456789, 2); // 123.46 M // with target language (default is english) $readableNumber = ReadableNumbers::make(123456789, 2, 'tr'); // 123.46 Mn $readableNumber = ReadableNumbers::make(123456789, 3, 'ja'); // 123.457 億 $readableNumber = ReadableNumbers::make(123456789, 4, 'de'); // 123.4568 Mio.
Directive Example
There is only one directive: @readableNumber(), again takes three arguments: @readableNumber(float $value, int $decimals = 1, $lang = null). If you use a multi-language system, you should remember to directives are cached. So, you should pass decimal count and language.
... <span> @readableNumber(123456789, 1, app()->getLocale()) </span> ... <span class="view-counter"> <i class="icon icon-eye"></i> Viewed @readableNumber($blogPost->views, 1, app()->getLocale()) times </span>
Languages
Supported languages are listed here and reference are used in unicode.org. If you want to add your own language and send PR.
Don't forget to these shortings are depends on a mathematical view.
laravel-ready/readable-numbers 适用场景与选型建议
laravel-ready/readable-numbers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.55k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2022 年 04 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「readable numbers」 「human readable numbers」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 laravel-ready/readable-numbers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laravel-ready/readable-numbers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 laravel-ready/readable-numbers 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Convert a value in seconds into a human-readable convenience duration
Partition problem for balanced arrays splitting made easy.
Extend laravel applications with more artisan commands, traits and useful helper classes
Rutils Symfony 2 bundle
Generates human-readable strings for PHP DateTime objects
JavaScript library to generate a human readable String describing the file size
统计信息
- 总下载量: 13.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 13
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-04-22