Roman Numerals From Integers | ||
| ||
/* Ported to JScript from a VBS script by Bill Wilkinson all rights for this implementation - jason@atrax.co.uk you may reuse this code as you see fit. modifications should be re-released into the public domain, and a copy emailed to the author(s). http://www.infinitemonkeys.ws/ */ function getNumeral(intNum) { var arrDigits = new Array("I","V","X","L","C","D","M", "<U>V</U>","<U>X</U>","<U>L</U>", "<U>C</U>","<U>D</U>","<U>M</U>", "?","?"); if(intNum<0||intNum>39999999) { return "Error"; } var result = ''; for(var x=0;x<7;x++) { intDig = intNum % 10; intStartD = x * 2; one = arrDigits[intStartD]; five = arrDigits[intStartD+1]; ten = arrDigits[intStartD+2]; if(intDig==9) { result = one + ten + result; } else if(intDig==4) { result = one + five + result; } else { var temp = ""; if(intDig >= 5) { temp = five; } for(i=1;i<=(intDig%5);i++) { temp += one; } result = temp + result; } intNum = parseInt(intNum/10); } return result ; } WScript.Echo(getNumeral(1979)) | ||
| | ||
| |