CurrencyValue
Provides factory methods and arithmetic operations for CurrencyValue.
Attributes
- Source
- number.scala
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
CurrencyValue.type
Members list
Value members
Concrete methods
Adds augend to a CurrencyValue.
Adds augend to a CurrencyValue.
Attributes
- Note
-
Using
Doublecan lead to precision inaccuracies. - Source
- number.scala
Creates a CurrencyValue from a BigDecimal, Long, Int, or Double.
Creates a CurrencyValue from a BigDecimal, Long, Int, or Double.
Value parameters
- value
-
A CurrencyValue, BigDecimal, Long, Int, or Double to create a
CurrencyValuefrom.
Attributes
- Returns
-
A new
CurrencyValueinstance. - Note
-
Using
Doublecan lead to floating-point precision inaccuracies becauseDoubleis a binary floating point number, and cannot precisely represent some decimal values. This can lead to unexpected rounding or comparison results. - Example
-
import world.money.currency.CurrencyValue val value1: CurrencyValue = CurrencyValue(10.5) val value2: CurrencyValue = CurrencyValue(100L) - Source
- number.scala
Attempts to divide a CurrencyValue by divisor.
Attempts to divide a CurrencyValue by divisor.
Attributes
- Returns
-
Rightwith the result, orLeftcontaining an world.money.errors.ArithmeticError if division fails (e.g. division by zero). - Note
-
Using
Doublecan lead to precision inaccuracies. - Source
- number.scala
Attempts to create a CurrencyValue from a String representation.
Attempts to create a CurrencyValue from a String representation.
This is a preferred method for constructing CurrencyValue instances when the source value is not already a BigDecimal, as it avoids binary floating-point inaccuracies.
Value parameters
- context
-
A world.money.currency.CurrencyMathContext given instance for decimal precision and rounding.
- value
-
The string to parse into a CurrencyValue.
Attributes
- Returns
-
An
Eithercontaining either a NumberFormattingError if parsing fails, or the resultingCurrencyValue. - Example
-
import world.money.currency.CurrencyValue CurrencyValue.fromString("123.45") match { case Right(value) => println(s"Value: $value") case Left(error) => println(s"Error: ${error.message}") } - Source
- number.scala
Multiplies a CurrencyValue by multiplicand.
Multiplies a CurrencyValue by multiplicand.
Attributes
- Note
-
Using
Doublecan lead to precision inaccuracies. - Source
- number.scala
Subtracts subtrahend from a CurrencyValue.
Subtracts subtrahend from a CurrencyValue.
Attributes
- Note
-
Using
Doublecan lead to precision inaccuracies. - Source
- number.scala
Unwraps a CurrencyValue to its underlying BigDecimal.
Represents a constant CurrencyValue with a value of zero.
Givens
Extensions
Extensions
Multiplies this CurrencyValue by a value.
Multiplies this CurrencyValue by a value.
Attributes
- Note
-
Using
Doublecan lead to precision inaccuracies. - Source
- number.scala
Adds a value to this CurrencyValue.
Adds a value to this CurrencyValue.
Attributes
- Note
-
Using
Doublecan lead to precision inaccuracies. - Source
- number.scala
Subtracts a value from this CurrencyValue.
Subtracts a value from this CurrencyValue.
Attributes
- Note
-
Using
Doublecan lead to precision inaccuracies. - Source
- number.scala
Attributes
- Source
- number.scala
Returns the absolute value of this CurrencyValue.
Negates this CurrencyValue.
Negates this CurrencyValue.
Attributes
- Returns
-
A new
CurrencyValuerepresenting the negation of this value. - Source
- number.scala
Returns the signum of this CurrencyValue: -1 (negative), 0 (zero), or 1 (positive).
Returns the signum of this CurrencyValue: -1 (negative), 0 (zero), or 1 (positive).
Attributes
- Source
- number.scala
Negates this CurrencyValue.
The raw BigDecimal representation of this value.
Returns a CurrencyValue whose value is this CurrencyValue with the specified scale.
Returns a CurrencyValue whose value is this CurrencyValue with the specified scale.
This is useful for explicit rounding to a certain number of decimal places, which is distinct from the precision-based rounding of the contextual CurrencyMathContext.
Value parameters
- roundingMode
-
The rounding mode to use.
- scale
-
Scale of the
CurrencyValueto be returned.
Attributes
- Returns
-
A
CurrencyValuewhose value is thisCurrencyValuewith the specified scale. - Source
- number.scala