PHP code example of yajima-tatsuro / jp-yen-formatter
1. Go to this page and download the library: Download yajima-tatsuro/jp-yen-formatter library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yajima-tatsuro / jp-yen-formatter example snippets
use JpYenFormatter\Converter;
// 千単位への変換
echo Converter::convert(1000, '千'); // "1千"
echo Converter::convert(1500, '千'); // "1.5千" (割り切れない場合は自動で小数点第一位まで)
// 万単位への変換
echo Converter::convert(10000, '万'); // "1万"
echo Converter::convert(15000, '万'); // "1.5万"
// 百万単位への変換
echo Converter::convert(1000000, '百万'); // "1百万"
echo Converter::convert(1500000, '百万'); // "1.5百万"
// 億単位への変換
echo Converter::convert(100000000, '億'); // "1億"
echo Converter::convert(150000000, '億'); // "1.5億"
use JpYenFormatter\Converter;
// 基本的な変換
$result = Converter::convert(5000, '千');
// 結果: "5千"
$result = Converter::convert(50000, '万');
// 結果: "5万"
// 割り切れない場合(デフォルトで小数点第一位まで表示)
$result = Converter::convert(1500, '千');
// 結果: "1.5千"
$result = Converter::convert(23000, '万');
// 結果: "2.3万"
// 小数点桁数を指定
$result = Converter::convert(12340, '千', 2);
// 結果: "12.34千"
$result = Converter::convert(123400, '万', 3);
// 結果: "12.34万"
// 大きな数値の自動フォーマット(カンマ区切り)
$result = Converter::convert(100000000000, '億');
// 結果: "1,000億"
$result = Converter::convert(100000000, '万');
// 結果: "10,000万"
// 未定義の単位を指定した場合
$result = Converter::convert(1000, '円');
// 結果: "1000円"
// 割り切れる場合
echo Converter::convert(2000, '千'); // "2千"
echo Converter::convert(30000, '万'); // "3万"
// 割り切れない場合
echo Converter::convert(1500, '千'); // "1.5千"
echo Converter::convert(23000, '万'); // "2.3万"
// 小数点第二位まで表示
echo Converter::convert(12340, '千', 2); // "12.34千"
// 小数点なし(整数のみ)
echo Converter::convert(1500, '千', 0); // "2千" (四捨五入)