thedevick/precise-money 问题修复 & 功能扩展

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

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

thedevick/precise-money

最新稳定版本:2.1.0

Composer 安装命令:

composer require thedevick/precise-money

包简介

Manipulate money precisely with PHP.

README 文档

README

NystronSolarBadge PHPUnitBadge PHPBadge PsalmBadge SemanticReleaseBadge

Precise Money

The Money Object

The Money class is an immutable class, that represent an amount of money. You can add, subtract, multiply and divide the amount in the object with numeric-string or other Money object. Also, the Money Class is Json Serializable and Stringable.

<?php

use TheDevick\PreciseMoney\Calculator\BCMathCalculator;
use TheDevick\PreciseMoney\Money;

$money = new Money('10', new BCMathCalculator(3)); // Start with $10.000, using the BCMathCalculator with scale 3 (The default is using scale 10)
$money = $money->addMoney(new Money('3')); // Add $3.000
$money = $money->add('5.235'); // Add $5.235

return json_encode($money); // Returns {"amount":"18.235"}

Internally

Internally, the Money object stores the amount in an numeric-string.

Why use Precise Money?

This package provides an way to calculate money precisely. In other libraries,that stores the amount as cents as an integer,you can't calculate, for example, the price per kWh, since the price per kWh usally have more than 4 decimals. But since the Precise Money package stores the amount as an numeric-string, you can store many decimals as you wan't.

Calculating

Today, we only have the BCMathCalculator available, that implements the CalculatorInterface.

Tests

Calculator

Custom Calculator Test Trait

To test calculator classes that implements the Calculator Interface, you can use the Calculator Test Trait. It have some methods that can help you write your tests:

  • generateCalculatorMessage(CalculatorInterface $calculator) Returns a nice message that says the Class and Scale of the Calculator. Useful with $message argument in assertions.
  • assertCalculatorAddMethod($calculator, $expected, $x, $y) This methods asserts the calculator add method.
  • assertCalculatorAddMethodComplete($calculator)nThis methods asserts many operations with the calculator.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-12