Skip to content

Formatting: Add function to format number to its roman number #116

Description

@Farkhanda-Dalal

Description:
The formatRomanNumeral(num) function will convert a positive integer into its Roman numeral representation.
It should support values from 1 up to at least 3999 (standard Roman numeral system).

Acceptance Criteria:

1     → "I"
4     → "IV"
9     → "IX"
58    → "LVIII"      // (50 + 5 + 3)
1994  → "MCMXCIV"    // (1000 + 900 + 90 + 4)
2025  → "MMXXV"
3999  → "MMMCMXCIX"
0     → ""           // return empty string or throw error for 0
-5    → Error        // invalid input
"123" → Error        // must be number

The function must:

  • Handle all valid integers in the range 1–3999.
  • Use subtractive notation (e.g., IV for 4, IX for 9, XL for 40, CM for 900).
  • Return an empty string or throw an error for 0 and negative numbers.
  • Throw a TypeError if the input is not a number.
  • Include comprehensive unit tests for edge cases (1, 4, 9, 3999, invalid inputs).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Level 3Hard level Issuegssoc25GSSOC'25 approved issue

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions