class

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 minus

Subtract b from this

compare

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

mod

Return remainder of this divided by b

mult

Multiply this with b

modInt

Return remainder of this divided by b

divFloat

Divide this by b

increment

Increment by one

multInt

Multiply this with b

div

Divide this by b

plusFloat

Add this with b

min

Return the smaller of this and the specified Decimal values

minusFloat

Subtract b from this

plusInt

Add this with b

modFloat

Return remainder of this divided by b

toStr

Get string representation

multFloat

Multiply this with b

toLocale

Format this decimal number for the current locale

max

Return the larger of this and the specified Decimal values

toCode

Get this Decimal as a Fantom code literal

plus

Add this with b

abs

Return the absolute value of this decimal

decrement

Decrement by one

minusInt

Subtract b from this

negate

Negative of this

equals

Return true if same decimal with same scale

divInt

Divide this by b

hash

Return platform specific hashcode

abs Decimal abs()

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

compare virtual 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 Bool equals(Obj? obj)

Return true if same decimal with same scale.

fromStr static new fromStr(Str s, Bool checked)

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

hash virtual 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, Locale locale)

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 Str toStr()

Get string representation.

Haxall 4.0.5 ∙ 24-Feb-2026 14:33 EST