Roman Numerical Converter

Developer
Size
2,102 Kb
Views
22,264

How do I make an roman numerical converter?

What is a roman numerical converter? How do you make a roman numerical converter? This script and codes were developed by Victor Hall on 23 September 2022, Friday.

Roman Numerical Converter Previews

Roman Numerical Converter - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Roman Numerical Converter</title>
</head>
<body> <!--<div id="test"></div>--> <script src="js/index.js"></script>
</body>
</html>

Roman Numerical Converter - Script Codes JS Codes

function convertToRoman(num) { var result = num; var answer = []; var temp = 0; //test if number is greater than or equal to 1000 if((result / 1000) >= 1){ temp = result; //Returns how many times the number goes into 1000 temp = temp / 1000; //rounds down to get a whole number temp = Math.floor(temp); //Adds that appropriate n quantities to the array for(var i = 0; i < temp; i++){ answer.push("M"); } //converts number in terms of 100 since there are not more // 1000s left in it result = result % 1000; } //This takes care of the special case //Since you cannot have 4 C's, this handles all //numbers between 900 to 10000 if((result < 1000) && (result >=900)){ answer.push("CM"); result = result - 900; } //test if number is greater than or equal to 500 if((result / 500) >= 1){ temp = 0; temp = result; //Returns how many times the number goes into 500 temp = temp / 500; //Rounds down temp = Math.floor(temp); for(var o = 0; o < temp; o++){ answer.push("D"); } //converts number in terms of 100 since there are not more // 500s left in it result = result % 500; }
if((result / 100) >= 1){ temp = 0; temp = result; temp = temp / 100; temp = Math.floor(temp); for(var p = 0; p < temp; p++){ answer.push("C"); } result = result % 100; } if((result < 100) && (result >= 90)){ answer.push("XC"); result = result - 90; }
if((result / 50) >= 1){ temp = 0; temp = result; temp = temp / 50; temp = Math.floor(temp); for(var a = 0; a < temp; a++){ answer.push("L"); } result = result % 50; } if((result / 10) >= 1){ temp = 0; temp = result; temp = temp / 10; temp = Math.floor(temp); if(temp > 3){ answer.push("XL") } if(temp <= 3){ for(var s = 0; s < temp; s++){ answer.push("X"); } } result = result % 10; } if(result == 9 ){ temp = 0; answer.push("IX"); result = result % 9; } if((result / 5) >= 1){ temp = 0; temp = result; temp = temp / 5; temp = Math.floor(temp); for(var f = 0; f < temp; f++){ answer.push("V"); } result = result % 5; } if((result / 1) >= 1){ temp = 0; temp = result; temp = temp / 1; temp = Math.floor(temp); if(temp > 3){ answer.push("IV") } if(temp <= 3){ for(var g = 0; g < temp; g++){ answer.push("I"); } } result = result % 1; } var list = answer.join(''); alert(list) //document.getElementById('').innerHTML = answer;
}
convertToRoman(3999);
Roman Numerical Converter - Script Codes
Roman Numerical Converter - Script Codes
Home Page Home
Developer Victor Hall
Username vhall_io
Uploaded September 23, 2022
Rating 3
Size 2,102 Kb
Views 22,264
Do you need developer help for Roman Numerical Converter?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Victor Hall (vhall_io) Script Codes
Create amazing sales emails with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!