Skip to content

newteng/format-cny

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

format-cny

一个简单的人民币数字转大写的工具,将1010.0559.995123456789.01等数字转换为壹拾圆整壹拾圆零陆分壹拾圆整壹亿贰仟叁佰肆拾伍万陆仟柒佰捌拾玖圆零壹分; 四舍五入自动保留2位小数,最大转换单位到亿

Installing

$ composer require newteng/format-cny -vvv

Usage

Common

<?php

require __DIR__ . '/vendor/autoload.php';

$c = new \Newteng\FormatCny\Cny();
echo $c->transform('1433') . PHP_EOL; //壹仟肆佰叁拾叁圆整
echo $c->transform('0.89') . PHP_EOL; //捌角玖分
echo $c->transform('11343') . PHP_EOL; //壹万壹仟叁佰肆拾叁圆整
echo $c->transform('0.001') . PHP_EOL; //零圆整

Laravel

<?php

namespace App\Http\Controllers;

use Newteng\FormatCny\Cny;

class IndexController extends Controller
{
    public function index(Cny $cny)
    {
//        return $cny->transform(10.055); // 壹拾圆零陆分
//        return $cny->transform(10.0); // 壹拾圆整
//        return $cny->transform(9.995); // 壹拾圆整
//        return $cny->transform(10.011); // 壹拾圆零壹分
        return $cny->transform(123456789.01); // 壹亿贰仟叁佰肆拾伍万陆仟柒佰捌拾玖圆零壹分
    }
}

License

MIT

About

A simple RMB formatting component.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages