Huruf Romawi di Nomor Invoice dari konversi angka? Biasanya sih Bulan yah, nih Dheezer kasih contoh fungsinya di pemrograman PHP dengan nama fungsi number_romawi, simak scriptnya di bawah ini yuk.
function number_romawi( $number )
{
$dictionary = [
1 => "I",
2 => "II",
3 => "III",
4 => "IV",
5 => "V",
6 => "VI",
7 => "VII",
8 => "VIII",
9 => "IX",
10 => "X",
11 => "XI",
12 => "XII",
13 => "XIII",
14 => "XIV",
15 => "XV",
16 => "XVI",
17 => "XVII",
18 => "XVIII",
19 => "XIX",
20 => "XX",
30 => "XXX",
40 => "XL",
50 => "L",
100 => "C",
500 => "D",
1000 => "M"
];
$arrNum = number_split($number)['nominal'];
$result = "";
for ( $n = 0; $n < count($arrNum); $n++ )
{
for ( $i = 0; $i < count($arrNum[$n]); $i++ )
{
if ( isset($dictionary[ $arrNum[$n][$i] ]) )
{
$result .= $dictionary[ $arrNum[$n][$i] ];
}
else
{
$listK = array_keys($dictionary);
$p = 0;
$nexK = 0;
$selK = 0;
while ( ($selK = $listK[$p]) && (int) $selK < (int) $arrNum[$n][$i] && (int) $arrNum[$n][$i] < 10000 )
{
$p++;
}
$selK = $listK[ $p - 1 ];
$nexK = (string) ((int) $arrNum[$n][$i] - (int) $selK);
$nexK = (string) ((int) $arrNum[n][i] - (int) $selK);
if ( isset($dictionary[ $selK ]) )
$result .= $dictionary[ $selK ];
if ( isset($dictionary[ $nexK ]) )
$result .= $dictionary[ $nexK ];
}
}
}
return $result;
}
Semoga ilmu ini bermanfaat dan tetap semangat berkarya gaes….