Created
November 3, 2016 00:25
-
-
Save yudaprawira/d4fbc555796fb1bae025068963345da2 to your computer and use it in GitHub Desktop.
Konversi Angka dari desimal ke romawi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toRomawi(angka) | |
{ | |
var desc = [1,4,5,9,10,40,50,90,100,400,500,900,1000]; | |
var roma = ["I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"]; | |
var hasil=''; | |
for(var i=12; i >=0; i--) | |
{ | |
while(angka >= desc[i]) | |
{ | |
angka-= desc[i]; | |
hasil+= roma[i]; | |
} | |
} | |
return hasil; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toRomawi($angka) | |
{ | |
$desc = [1,4,5,9,10,40,50,90,100,400,500,900,1000]; | |
$roma = ["I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"]; | |
$hasil=''; | |
for($i=12; $i>=0; $i--) | |
{ | |
while($angka >= $desc[$i]) | |
{ | |
$angka-= $desc[$i]; | |
$hasil.= $roma[$i]; | |
} | |
} | |
return $hasil; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment