* Translates given decimal to roman numerals. * @protected * @param {Number|BigInt} decimal Decimal value (1-3999) * @return {?string} Roman numerals or null, if not defined
(decimal)
| 218 | * @return {?string} Roman numerals or null, if not defined |
| 219 | */ |
| 220 | static decimalToRomanNumerals (decimal) { |
| 221 | if (decimal <= 0 || decimal >= 4000) { |
| 222 | return null |
| 223 | } |
| 224 | |
| 225 | let remainder = Number(decimal) |
| 226 | let romanNumerals = '' |
| 227 | let numeral |
| 228 | |
| 229 | while (remainder > 0) { |
| 230 | // Find highest roman numeral less or equal to the decimal |
| 231 | numeral = romanNumeralValues.findIndex(value => remainder >= value) |
| 232 | // Add digit |
| 233 | romanNumerals += romanNumeralSymbols[numeral] |
| 234 | // Substract roman mumeral from remainder |
| 235 | remainder -= romanNumeralValues[numeral] |
| 236 | } |
| 237 | |
| 238 | return romanNumerals |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Translates given roman numerals to decimal. |