Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///integer_to_roman(string);
- /*
- ** Usage:
- ** integer_to_roman(string);
- **
- ** Argument:
- ** string String to convert
- **
- ** Returns:
- ** The string converted into roman numerals.
- */
- //Temporary string
- var str = "";
- //Given input
- input = argument[0];
- //First, let's check the input.
- if ((input < 1) || (input > 3999)) { //If the number is lower than 1 or greater than 3999.
- exit;
- }
- //Otherwise, convert the input into roman numerals.
- else {
- //1000 into "M".
- while (input >= 1000) { str += "M"; input -= 1000; }
- //900 into "CM".
- while (input >= 900) { str += "CM"; input -= 900; }
- //500 into "D".
- while (input >= 500) { str += "D"; input -= 500; }
- //400 into "CD".
- while (input >= 400) { str += "CD"; input -= 400; }
- //100 into "C".
- while (input >= 100) { str += "C"; input -= 100; }
- //90 into "XC".
- while (input >= 90) { str += "XC"; input -= 90; }
- //50 into "L".
- while (input >= 50) { str += "L"; input -= 50; }
- //40 into "XL".
- while (input >= 40) { str += "XL"; input -= 40; }
- //10 into "X".
- while (input >= 10) { str += "X"; input -= 10; }
- //9 into "IX".
- while (input >= 9) { str += "IX"; input -= 9; }
- //5 into "V".
- while (input >= 5) { str += "V"; input -= 5; }
- //4 into "IV".
- while (input >= 4) { str += "IV"; input -= 4; }
- //1 into "I".
- while (input >= 1) { str += "I"; input -= 1; }
- }
- //Return the obtained string
- return str;
Add Comment
Please, Sign In to add comment