MCPcopy Create free account
hub / github.com/cryptii/cryptii / decimalToRomanNumerals

Method decimalToRomanNumerals

src/Encoder/NumeralSystem.js:220–239  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Callers 1

encodeNumberMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected