CurrencyValue

world.money.currency.number$package.CurrencyValue
object CurrencyValue

Provides factory methods and arithmetic operations for CurrencyValue.

Attributes

Source
number.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

inline def add(value: CurrencyValue, augend: CurrencyValue | BigDecimal | Long | Int | Double)(using CurrencyMathContext): CurrencyValue

Adds augend to a CurrencyValue.

Adds augend to a CurrencyValue.

Attributes

Note

Using Double can lead to precision inaccuracies.

Source
number.scala
inline def apply(value: CurrencyValue | BigDecimal | Long | Int | Double)(using CurrencyMathContext): CurrencyValue

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 CurrencyValue from.

Attributes

Returns

A new CurrencyValue instance.

Note

Using Double can lead to floating-point precision inaccuracies because Double is 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
inline def divide(value: CurrencyValue, divisor: CurrencyValue | BigDecimal | Long | Int | Double)(using CurrencyMathContext): Either[ArithmeticError, CurrencyValue]

Attempts to divide a CurrencyValue by divisor.

Attempts to divide a CurrencyValue by divisor.

Attributes

Returns

Right with the result, or Left containing an world.money.errors.ArithmeticError if division fails (e.g. division by zero).

Note

Using Double can lead to precision inaccuracies.

Source
number.scala
inline def fromString(value: String)(using CurrencyMathContext): Either[NumberFormattingError, CurrencyValue]

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 Either containing either a NumberFormattingError if parsing fails, or the resulting CurrencyValue.

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
inline def multiply(value: CurrencyValue, multiplicand: CurrencyValue | BigDecimal | Long | Int | Double)(using CurrencyMathContext): CurrencyValue

Multiplies a CurrencyValue by multiplicand.

Multiplies a CurrencyValue by multiplicand.

Attributes

Note

Using Double can lead to precision inaccuracies.

Source
number.scala
inline def subtract(value: CurrencyValue, subtrahend: CurrencyValue | BigDecimal | Long | Int | Double)(using CurrencyMathContext): CurrencyValue

Subtracts subtrahend from a CurrencyValue.

Subtracts subtrahend from a CurrencyValue.

Attributes

Note

Using Double can lead to precision inaccuracies.

Source
number.scala
inline def unwrap(value: CurrencyValue): BigDecimal

Unwraps a CurrencyValue to its underlying BigDecimal.

Unwraps a CurrencyValue to its underlying BigDecimal.

Attributes

Source
number.scala

Represents a constant CurrencyValue with a value of zero.

Represents a constant CurrencyValue with a value of zero.

Attributes

Source
number.scala

Givens

Extensions

Extensions

extension (value: CurrencyValue)
inline def *(multiplicand: BigDecimal | Long | Int | Double)(using CurrencyMathContext): CurrencyValue

Multiplies this CurrencyValue by a value.

Multiplies this CurrencyValue by a value.

Attributes

Note

Using Double can lead to precision inaccuracies.

Source
number.scala
inline def +(augend: CurrencyValue | BigDecimal | Long | Int | Double)(using CurrencyMathContext): CurrencyValue

Adds a value to this CurrencyValue.

Adds a value to this CurrencyValue.

Attributes

Note

Using Double can lead to precision inaccuracies.

Source
number.scala
inline def -(subtrahend: CurrencyValue | BigDecimal | Long | Int | Double)(using CurrencyMathContext): CurrencyValue

Subtracts a value from this CurrencyValue.

Subtracts a value from this CurrencyValue.

Attributes

Note

Using Double can lead to precision inaccuracies.

Source
number.scala
inline def /(divisor: CurrencyValue | BigDecimal | Long | Int | Double)(using CurrencyMathContext): Either[ArithmeticError, CurrencyValue]

Attributes

Source
number.scala

Returns the absolute value of this CurrencyValue.

Returns the absolute value of this CurrencyValue.

Attributes

Source
number.scala

Negates this CurrencyValue.

Negates this CurrencyValue.

Attributes

Returns

A new CurrencyValue representing the negation of this value.

Source
number.scala
transparent inline def signum: Int

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.

Negates this CurrencyValue.

Attributes

Source
number.scala
inline def unwrap: BigDecimal

The raw BigDecimal representation of this value.

The raw BigDecimal representation of this value.

Attributes

Source
number.scala
inline def withScale(scale: Int, roundingMode: RoundingMode): CurrencyValue

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 CurrencyValue to be returned.

Attributes

Returns

A CurrencyValue whose value is this CurrencyValue with the specified scale.

Source
number.scala