定制 xxc/fractionmath 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

xxc/fractionmath

Composer 安装命令:

composer create-project xxc/fractionmath

包简介

Package for doing math operations with Fractions

README 文档

README

Latest Version Software License Build Status

Auto simplifies the fractions on initialisation. Installation:

 composer require xxc/fractionmath:1.*

Usage:

$fraction = new Fraction(1,2);
$fraction->display();

Available methods for a Fraction:

  • numerator() - gets the numerator
  • denominator() - gets the denominator
  • integer() - gets the integer
  • getGreatestCommonDivisor() - gets the GCD of the numetor and the denominator
  • getFractionAsArray() - returns the fraction as array with keys numerator, denominator, integer
  • getFractionAsObject() - returns the fraction as object
  • display() - returns the html for a fraction
  • parse() - static method for quick parsing strings to fractions

Works with irregular fractions aswell
$fraction = new Fraction(9,3);
$fraction->getFractionAsArray(); 
/*
returns ...
  array(
    'numerator' => 9,
    'denominator' => 3,
    'integer' => 0
    );
    */

If you need you can parse strings to fractions with the static parse method. The method accepts a string param in the format integer-space-nominator-slash-deniminator - Example for valid inputs: 1/2; 5 1/2; 5/6; 666 1/5;

xxc\fractionmath\Fraction::parse('1/2'); \\returns a fraction with nominator 1 and denominator 2
xxc\fractionmath\Fraction::parse('3 1/2'); \\returns a fraction with integer 3,nominator 1 and denominator 2
\\you can chain methods like this
xxc\fractionmath\Fraction::parse('2/4')->display(); \\returns html for a fraction 2/4

The Math class handles all the math operations - requires Fraction as inputs and returns a Fraction
Math operations:

  • add()
  • subtract()
  • multiply()
  • divide()
$fractionOne = new Fraction(1,3);
$fractionTwo = new Fraction(1,3);

$mathOperation = new Math();

$mathOperation->add($fractionOne, $fractionTwo);
$mathOperation->subtract($fractionOne, $fractionTwo);
$mathOperation->multiply($fractionOne, $fractionTwo);
$mathOperation->divide($fractionOne, $fractionTwo);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固