How To Create Converter For Decimal To Roman Numeral
Submitted by alpha_luna on Thursday, April 28, 2016 - 16:04.
Related Code: Converter For Decimal To Binary
Related Code: Converter For Binary To Decimal
If you are looking for another converter then you are at the right place and it’s called Converter For Decimal To Roman Numeral. The user input a value of Decimal Number to the textbox then the program will convert to Roman Numeral after the user clicks the Convert button. This program is very easy and you can do this also.
Note: The input must be in the range of 1 to 4999, or I to MMMMCMXCIX.
JavaScript Code
This script will ask the user to enter a Decimal Number then the script also converts automatically into Roman Numeral.
This is the output after the user types the Decimal Number.
Related Code: Converter For Decimal To Binary
Related Code: Converter For Binary To Decimal
So what can you say about this work? Share your thoughts in the comment section below or email me at [email protected]. Practice Coding. Thank you very much.
- <script language="javascript" type="text/javascript">
- function convert_to_roman(val)
- {
- var roman_numerals=['I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC', 'C', 'CD', 'D', 'CM', 'M'];
- var list_numbers=[1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000];
- var x = parseInt(val);
- if( x<1 || x>4999 )
- {
- alert(x+' number is out of range.');
- return 0;
- }
- display_result = '';
- for(a=12; a>=0;)
- if( list_numbers[a]<=x )
- {
- display_result += roman_numerals[a];
- x -= list_numbers[a];
- }
- else
- {
- a--;
- }
- return(display_result);
- }
- $(document).ready(function () {
- value_number = parseInt(prompt("Enter a Decimal Number to Convert into Roman Numeral"));
- document.write("<h3 style='text-align:center; margin-top: 100px;'><b style='color:blue;'>"+value_number + "</b> is equivalent to <b style='color:red;'>" +
- convert_to_roman(value_number) + "</b> in roman numerals. </h3>");
- });
- </script>
Add new comment
- 35 views