php百分比还原值,一个用于处理百分比数值的PHP包

A PHP package to work with percentages

A clean interface to calculate percentages in PHP: changes between values, percentage increases, partial values, extensions, ...

Think of it as a very lightweight math library for the basic stuff. Aimed to make your code more readable and easier to understand.

Installation

You can install the package via composer:

composer require mattiasgeniar/php-percentages

Usage

use Mattiasgeniar\Percentage\Percentage;

// What's the percentage increase from 100 to 120?

Percentage::differenceBetween(100, 120); // 20%

// What's the absolute percentage change from 100 to 80?

// (uses the abs() function)

Percentage::absoluteDifferenceBetween(100, 80); // 20%, not -20%

// How much is 120 compared to 100?

Percentage::calculate(120, 100); // 120%

// How much is 50 compared to 100?

Percentage::calculate(50, 100); // 50%

// What is 20% of 200?

Percentage::of(20, 200); // 40

// What is the 140% extension from 3 to 2?

Percentage::extension(140, 3, 2); // 1.6

// What is the 140% extension from 1 to 2?

Percentage::extension(140, 1, 2); // 2.4

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email m@ttias.be instead of using the issue tracker.

Credits

License

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值