type

Decimal

@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

Decimal abs()

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

compare

virtual override Int compare(Obj obj)

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

decrement

@Operator
Decimal decrement()

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

defVal

const static Decimal defVal

Default value is 0.

div

@Operator
Decimal div(Decimal b)

Divide this by b. Shortcut is a/b.

divFloat

@Operator
Decimal divFloat(Float b)

Divide this by b. Shortcut is a/b.

divInt

@Operator
Decimal divInt(Int b)

Divide this by b. Shortcut is a/b.

equals

virtual override Bool equals(Obj? obj)

Return true if same decimal with same scale.

fromStr

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

virtual override Int hash()

Return platform specific hashcode.

increment

@Operator
Decimal increment()

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

max

Decimal max(Decimal that)

Return the larger of this and the specified Decimal values.

min

Decimal min(Decimal that)

Return the smaller of this and the specified Decimal values.

minus

@Operator
Decimal minus(Decimal b)

Subtract b from this. Shortcut is a-b.

minusFloat

@Operator
Decimal minusFloat(Float b)

Subtract b from this. Shortcut is a-b.

minusInt

@Operator
Decimal minusInt(Int b)

Subtract b from this. Shortcut is a-b.

mod

@Operator
Decimal mod(Decimal b)

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

modFloat

@Operator
Decimal modFloat(Float b)

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

modInt

@Operator
Decimal modInt(Int b)

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

mult

@Operator
Decimal mult(Decimal b)

Multiply this with b. Shortcut is a*b.

multFloat

@Operator
Decimal multFloat(Float b)

Multiply this with b. Shortcut is a*b.

multInt

@Operator
Decimal multInt(Int b)

Multiply this with b. Shortcut is a*b.

negate

@Operator
Decimal negate()

Negative of this. Shortcut is -a.

plus

@Operator
Decimal plus(Decimal b)

Add this with b. Shortcut is a+b.

plusFloat

@Operator
Decimal plusFloat(Float b)

Add this with b. Shortcut is a+b.

plusInt

@Operator
Decimal plusInt(Int b)

Add this with b. Shortcut is a+b.

toCode

Str toCode()

Get this Decimal as a Fantom code literal.

toLocale

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

virtual override Str toStr()

Get string representation.