stonec0der/shorten-nums 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

stonec0der/shorten-nums

Composer 安装命令:

composer require stonec0der/shorten-nums

包简介

Shorten some numbers to this notation 1000 => 1K.

README 文档

README

Latest Version on Packagist Build Status Quality Score Total Downloads License: MIT

This is simple package to convert 12894090 views to 12.9M views. Feel free to use.

Installation

You can clone this repo

git clone https://github.com/stoneC0der/laravel-shorten-nums.git

Or via composer:

composer require stonec0der/shorten-nums

Publish the configuration file with

php artisant vendor:publish --provider="Stonec0der\ShortenNums\ShortenNumsServiceProvider"

This will publish a config file shorten-nums.php in the config folder. Set your default precision

Usage

Let's say you have a big integer value being return like 12894090 (views) and you want to display it like this 12.8M (views).

use Stonec0der\ShortenNumsFacade

...
$value = '12894090';
// Shorten
$formated_number = ShortenNumsFacade::readableNumber($value);

// Output will
// 12.9M.

If you do not need the config file you can directly pass the precision when calling any method, else the default will be use

/*
Default
This enable you to return for 1240 => 1.2K with default precisionn
and 1.24 with $precision set to 2 and so on.
*/
$value = '1240';
$precision = 2;

$formated_number = ShortenNumsFacade::readableNumber($value, $precision);
// Output
// 1.24K

If you expect the value to be between 999,999 & 999,999,999. You can directly call a method associated with Millions

$value = '8525000';
$formated_number = ShortenNumsFacade::readableMillion($value, 2);
// Output
// 8.53M

In most case you will want to use ShortenNumsFacade::readableNumer($number);. If a value less than 999 is passed the value is return as it, if it greater than 999 Trillions return // 999+T

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email stonec0dersoft@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固