Compares this Value Object with another for equality. Value Objects are equal if they are of the same type and all equality components match.
The other Value Object to compare with
true if the Value Objects are equal, false otherwise
StaticfromCreates a Percentage from a decimal value (0-1).
The decimal value (e.g., 0.25 for 25%)
Success with Percentage or Failure with DomainError
StaticfromCreates a Percentage from a percentage value (0-100).
The percentage value (e.g., 25 for 25%)
Success with Percentage or Failure with DomainError
StaticzeroStaticfullAdds another percentage to this one.
The percentage to add
Success with new Percentage or Failure if result exceeds 100%
Subtracts another percentage from this one.
The percentage to subtract
Success with new Percentage or Failure if result is negative
Multiplies this percentage by a factor.
The multiplication factor
Success with new Percentage or Failure if result exceeds 100%
Formats the percentage as a string.
Number of decimal places (default: 0)
A formatted string representation
ProtectedgetReturns the components that determine equality for this Value Object. Two Value Objects are equal if all their equality components are equal.
An array of values used for equality comparison
Returns a string representation of an object.
Represents a percentage value with validation and formatting.
Percentage is immutable and can be created from decimal (0.5) or percentage (50) values. Supports common percentage operations and formatting.
Example