コード
<?php
foreach ([120000001, 20000000, 20020000, 1020000, 120000,12000, 1001] as $number){
$oku = floor($number / 100000000);
$man = floor(($number % 100000000) / 10000);
$sen = ($number % 10000);
$result = implode('', array_filter([
($oku > 0 ? number_format($oku). '億' : ''),
($man > 0 ? number_format($man). '万' : ''),
($sen > 0 ? number_format($sen) : '')
])) ?: '0';
echo $result.PHP_EOL;
}
結果
1億2,000万1
2,000万
2,002万
102万
12万
1万2,000
1,001