Convert a Number into Roman Numerals

JavaScript used to convert given numeric values to roman numerals. Simply enter a number in the appropriate space below and click on the Convert button.

Features

  • Used to display the roman value of the given number.
  • Provides easy accessibility.

Preview

Enter the Number:
Roman Value:
©h

Downloads

Javascript Code


<!-- Script by hscripts.com -->
<!-- More scripts @www.hscripts.com -->
<style type="text/css">
.txt{border:1px solid grey;width:150px;height:25px;font-size:12px;padding:5px;}
.fnt{font-size:12px;font-family:arial,verdana;}
</style>
<script type="text/javascript">
function convert_roman()
{var narr=new Array("1000000","900000","500000","400000","100000","90000","50000","40000","10000","9000","5000","4000","1000","900","500","400","100","90","50","40","10","9","5","4","1");var rarr=new Array("<span style='text-decoration: overline'>M</span>","<span style='text-decoration: overline'>CM</span>","<span style='text-decoration: overline'>D</span>","<span style='text-decoration: overline'>CD</span>","<span style='text-decoration: overline'>C</span>", "<span style='text-decoration: overline'>XC</span>","<span style='text-decoration: overline'>L</span>","<span style='text-decoration: overline'>XL</span>","<span style='text-decoration: overline'>X</span>","<span style='text-decoration: overline'>IX</span>","<span style='text-decoration: overline'>V</span>","<span style='text-decoration: overline'>IV</span>","M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I");var num = parseInt(document.getElementById("num").value);if(num > 3999999 || num < 1){alert("Please enter a number between 1 and 3,999,999");return;}var result = "";var chk = num;while (chk > 0 ){var i;for (i=0; i<narr.length; i++){if(chk >= narr[i] ){result += rarr[i];chk -= narr[i];break;}}}document.getElementById("res").innerHTML=result;
}
function isinteger(s)
{var i;s = s.toString();for (i = 0; i < s.length; i++){var c = s.charAt(i);if (isNaN(c)) {alert("Given value is not a number");return false;}}return true;
}
</script>
<!-- Script by hscripts.com -->


HTML Code


<table>
<tr><td class="fnt">Enter the Number:</td><td><input type="text" class="txt" id="num" value="" onkeyup="isinteger(this.value); convert_roman();"></td></tr>
<tr><td class="fnt">Roman Value:</td><td class="fnt"><div id="res" style='border:1px solid grey;height:20px; padding: 2px; padding-left: 8px;'></div></td></tr>
<tr><td colspan=2><div align=center style="font-size: 10px; color:green;" id="dumdiv">
<a href="https://www.hscripts.com" id="dum" style="text-decoration:none; color: #dadada;">©h</a>
</div></td></tr>
</table>


  • Release Date - 06-05-2010
  • Get free version without ©copyright link for just $10/-
  • For customization of this script or any script development, mail to support@hscripts.com

Usage

  • Copy and paste the javascript code into your HTML page and make use of this.
  • Here, the function "convert_roman()" is used to convert numeric value to roman numerals.

License

Related Scripts

Free Javascript Scripts


Ask Questions

Ask Question