mattiasgeniar/php-percentages 问题修复 & 功能扩展

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

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

mattiasgeniar/php-percentages

最新稳定版本:1.3.0

Composer 安装命令:

composer require mattiasgeniar/php-percentages

包简介

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

README 文档

README

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

<?php
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

Helper functions

The above expressions can also be used through a variety of helper functions:

  • percentage()
  • percentage_between()
  • percentage_abs_between()
  • percentage_of()
  • percentage_extension()

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.

统计信息

  • 总下载量: 297.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 203
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 201
  • Watchers: 6
  • Forks: 20
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固