定制 ruchengtang/cny 二次开发

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

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

ruchengtang/cny

Composer 安装命令:

composer require ruchengtang/cny

包简介

CNY helps you convert RMB from digital amount to uppercase. 人民币小写转换成大写

README 文档

README

CNY is a php library helps you convert RMB from digital amount to uppercase.

Requirement

  1. PHP >= 5.4

Installation

You can install the package via composer:

composer require ruchengtang/cny -vvv

Usage

use Ruchengtang\CNY\CNY;

$cny = new CNY();

// An empty string will be returned if the conversion fails:
$cny->convert(8888);

or

use Ruchengtang\CNY\CNY;
use Ruchengtang\CNY\Exception\ExceptionInterface;

$cny = new CNY();

try {
    // Conversion failure will throw an exception:
    $cny->convertOrFail(8888);
} catch (ExceptionInterface $e) {
    // ...
}

Supported formats for digital amounts

// String is welcome:
$cny->convert('911911911'); // 人民币玖亿壹仟壹佰玖拾壹万壹仟玖佰壹拾壹元
$cny->convert('8,901,234,567,890.12'); // 人民币捌万玖仟零壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾元壹角贰分
$cny->convert('.79'); // 人民币柒角玖分

// Decimal digits are supported:
$cny->convert(8888); // 人民币捌仟捌佰捌拾捌元
$cny->convert(0.36); // 人民币叁角陆分
$cny->convert(.23); // 人民币贰角叁分

// Support negative amounts:
$cny->convert('-8,888,888,888,888'); // 人民币负捌万捌仟捌佰捌拾捌亿捌仟捌佰捌拾捌万捌仟捌佰捌拾捌元
$cny->convert(-0.98); // 人民币负玖角捌分
$cny->convert(-1314); // 人民币负壹仟叁佰壹拾肆元

// Support up to 2 decimals:
$cny->convert(0.3978); // 人民币叁角玖分
$cny->convert('0.397,8'); // 人民币叁角玖分
$cny->convert(0.39); // 人民币叁角玖分

Unsupported formats for digital amounts

// Unsupported empty:
$cny->convertOrFail(''); // Ruchengtang\CNY\Exception\InvalidArgumentException: Cny must not be empty!
$cny->convertOrFail(null); // Ruchengtang\CNY\Exception\InvalidArgumentException: Cny must not be empty!

// Unsupported invalid characters:
$cny->convertOrFail(' '); // Ruchengtang\CNY\Exception\InvalidArgumentException: Cny contains invalid characters!
$cny->convertOrFail('12 '); // Ruchengtang\CNY\Exception\InvalidArgumentException: Cny 12 contains invalid characters!
$cny->convertOrFail('a.49'); // Ruchengtang\CNY\Exception\InvalidArgumentException: Cny a.49 contains invalid characters!

// Unsupported invalid format:
$cny->convertOrFail('1,23'); // Ruchengtang\CNY\Exception\InvalidArgumentException: Cny 1,23 invalid format!
$cny->convertOrFail('0.3,978'); // Ruchengtang\CNY\Exception\InvalidArgumentException: Cny 0.3,978 invalid format!
$cny->convertOrFail('1,22,3'); // Ruchengtang\CNY\Exception\InvalidArgumentException: Cny 1,22,3 invalid format!

// Unsupported too large, maximum support to 9999999999999.99:
$cny->convertOrFail(9999999999999.991); // Ruchengtang\CNY\Exception\RangeException: Cny 1.0E+13 contains invalid characters!

Don't display 人民币 symbol

Display 人民币 symbol by default, If you wish not to display:

$cny->convert(8888, false); // 捌仟捌佰捌拾捌元
$cny->convertOrFail(8888, false); // 捌仟捌佰捌拾捌元

Available Methods

The following methods are available:

Ruchengtang\CNY\CNYInterface
<?php

namespace Ruchengtang\CNY;

interface CNYInterface
{
    /**
     * Convert CNY from digital amount to uppercase or throw an exception.
     *
     * @param string|int|float $cny    CNY digital
     * @param bool             $symbol CNY symbol
     *
     * @return string
     */
    public function convertOrFail($cny, $symbol = true);

    /**
     * Convert CNY from digital amount to uppercase.
     *
     * @param string|int|float $cny    CNY digital
     * @param bool             $symbol CNY symbol
     *
     * @return string
     */
    public function convert($cny, $symbol = true);
}

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

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

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固