type

Decimal

src @Serializable { simple=true }
const class Decimal : Num

Decimal is used to represent a decimal floating point more precisely than a Float. Decimal is the preferred numeric type for financial applications.

constructors

fromStr

Parse a Str into a Decimal.

fields

defVal

Default value is 0.

methods

abs

Return the absolute value of this decimal.

compare

Compare based on decimal value, scale is not considered for equality (unlike equals).

decrement

Decrement by one.

div

Divide this by b.

divFloat

Divide this by b.

divInt

Divide this by b.

equals

Return true if same decimal with same scale.

hash

Return platform specific hashcode.

increment

Increment by one.

max

Return the larger of this and the specified Decimal values.

min

Return the smaller of this and the specified Decimal values.

minus

Subtract b from this.

minusFloat

Subtract b from this.

minusInt

Subtract b from this.

mod

Return remainder of this divided by b.

modFloat

Return remainder of this divided by b.

modInt

Return remainder of this divided by b.

mult

Multiply this with b.

multFloat

Multiply this with b.

multInt

Multiply this with b.

negate

Negative of this.

plus

Add this with b.

plusFloat

Add this with b.

plusInt

Add this with b.

toCode

Get this Decimal as a Fantom code literal.

toLocale

Format this decimal number for the current locale.

toStr

Get string representation.

Slot Details

abs

src Decimal abs()

Return the absolute value of this decimal. If this value is positive then return this, otherwise return the negation.

compare

src virtual override Int compare(Obj obj)

Compare based on decimal value, scale is not considered for equality (unlike equals).

decrement

src @Operator
Decimal decrement()

Decrement by one. Shortcut is --a or a--.

defVal

src const static Decimal defVal

Default value is 0.

div

src @Operator
Decimal div(Decimal b)

Divide this by b. Shortcut is a/b.

divFloat

src @Operator
Decimal divFloat(Float b)

Divide this by b. Shortcut is a/b.

divInt

src @Operator
Decimal divInt(Int b)

Divide this by b. Shortcut is a/b.

equals

src virtual override Bool equals(Obj? obj)

Return true if same decimal with same scale.

fromStr

src static new fromStr(Str s, Bool checked := true)

Parse a Str into a Decimal. If invalid format and checked is false return null, otherwise throw ParseErr.

hash

src virtual override Int hash()

Return platform specific hashcode.

increment

src @Operator
Decimal increment()

Increment by one. Shortcut is ++a or a++.

max

src Decimal max(Decimal that)

Return the larger of this and the specified Decimal values.

min

src Decimal min(Decimal that)

Return the smaller of this and the specified Decimal values.

minus

src @Operator
Decimal minus(Decimal b)

Subtract b from this. Shortcut is a-b.

minusFloat

src @Operator
Decimal minusFloat(Float b)

Subtract b from this. Shortcut is a-b.

minusInt

src @Operator
Decimal minusInt(Int b)

Subtract b from this. Shortcut is a-b.

mod

src @Operator
Decimal mod(Decimal b)

Return remainder of this divided by b. Shortcut is a%b.

modFloat

src @Operator
Decimal modFloat(Float b)

Return remainder of this divided by b. Shortcut is a%b.

modInt

src @Operator
Decimal modInt(Int b)

Return remainder of this divided by b. Shortcut is a%b.

mult

src @Operator
Decimal mult(Decimal b)

Multiply this with b. Shortcut is a*b.

multFloat

src @Operator
Decimal multFloat(Float b)

Multiply this with b. Shortcut is a*b.

multInt

src @Operator
Decimal multInt(Int b)

Multiply this with b. Shortcut is a*b.

negate

src @Operator
Decimal negate()

Negative of this. Shortcut is -a.

plus

src @Operator
Decimal plus(Decimal b)

Add this with b. Shortcut is a+b.

plusFloat

src @Operator
Decimal plusFloat(Float b)

Add this with b. Shortcut is a+b.

plusInt

src @Operator
Decimal plusInt(Int b)

Add this with b. Shortcut is a+b.

toCode

src Str toCode()

Get this Decimal as a Fantom code literal.

toLocale

src Str toLocale(Str? pattern := null, Locale locale := Locale.cur())

Format this decimal number for the current locale. If pattern is null, then the locale's default pattern is used. See Float.toLocale for pattern language and examples.

toStr

src virtual override Str toStr()

Get string representation.