RomanNumerals class
A class to convert between Roman and decimal numerals.
The class provides functionality to represent an integer as a Roman numeral and vice versa. For numbers greater than 3999, a bracket notation is used to represent multiplication by 1000.
Example:
var numeral = RomanNumerals(4567);
print(numeral); // Outputs: (IV)DLXVII
var numeralFromRoman = RomanNumerals.fromRoman('(IV)DLXVII');
print(numeralFromRoman.value); // Outputs: 4567
Constructors
- RomanNumerals.new(int value, {RomanNumeralsConfig? config, String zeroChar = 'N', bool useOverline = false})
-
Constructs a RomanNumerals object from a given integer
value
. - RomanNumerals.fromRoman(String roman, {RomanNumeralsConfig? config, String zeroChar = 'N', bool useOverline = false})
-
Constructs a RomanNumerals object from a given Roman numeral
roman
.
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- useOverline → bool
-
Determines if the numeral should use overline.
final
- value → int
-
The integer value represented by this instance.
final
- zeroChar → String
-
The character to represent zero.
final
Methods
-
isNegative(
) → bool - Since Roman numerals cannot be negative, this will always return false. However, it's added for consistency.
-
isPositive(
) → bool - Checks if the numeral is positive.
-
isZero(
) → bool - Checks if the numeral is zero.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toRoman(
{bool useOverline = false}) → String - Converts the integer value of this instance to a Roman numeral string.
-
toString(
) → String -
Returns the Roman numeral string representation of this instance.
override
Operators
-
operator %(
dynamic other) → RomanNumerals -
Euclidean modulo of this number by
other
. -
operator &(
dynamic other) → RomanNumerals - Bit-wise and operator.
-
operator *(
dynamic other) → RomanNumerals - Multiplies the values of two RomanNumerals objects and returns a new one.
-
operator +(
dynamic other) → RomanNumerals -
Adds the values of two
dynamic
objects and returns a new one. -
operator -(
dynamic other) → RomanNumerals - Subtracts the value of another RomanNumerals from this one and returns a new one.
-
operator /(
dynamic other) → RomanNumerals - Divides the value of this RomanNumerals by another and returns a new one.
-
operator <(
dynamic other) → bool - Check if this RomanNumerals is less than another and returns boolean value.
-
operator <<(
int shiftAmount) → RomanNumerals -
Shift the bits of this integer to the left by
shiftAmount
. -
operator <=(
dynamic other) → bool - Check if this RomanNumerals is less than or equal to another and returns boolean value.
-
operator ==(
Object other) → bool -
The equality operator.
override
-
operator >(
dynamic other) → bool - Check if this RomanNumerals is greater than another and returns boolean value.
-
operator >=(
dynamic other) → bool - Check if this RomanNumerals is greater than or equal to another and returns boolean value.
-
operator >>(
int shiftAmount) → RomanNumerals -
Shift the bits of this integer to the right by
shiftAmount
. -
operator ^(
dynamic other) → RomanNumerals - Bit-wise exclusive-or operator.
-
operator |(
dynamic other) → RomanNumerals - Bit-wise or operator
Static Properties
- romanNumeralsConfig ← RomanNumeralsConfig
-
Sets the RomanNumeralsConfig to be used globally for all RomanNumerals instances.
This allows customizing the behavior of the RomanNumerals class, such as the
representation of zero or the use of overline.
no getter
Static Methods
-
dateToRoman(
String date, {String sep = ' • ', String format = 'MMM-d, y'}) → String - Converts a date represented as a string to its Roman numeral representation.
-
isValidRoman(
String roman, {String zeroChar = 'N'}) → bool -
Validates if a given string
roman
is a valid Roman numeral. -
romanToDate(
String romanDate, {String sep = ' • ', String format = 'MMM-d, y'}) → String - Converts a Roman numeral representation of a date back to a standard date.