torreyatcitty/the-best-decimal/1.0.0

NOTE: the latest version is 1.1.0

Decimal

The datatype

type Decimal

The Decimal data type It is represented as mantissa * 10 ^ exponent

From stuff

fromInt : Int -> Decimal

Converts an Int to a Decimal

Converts an Int to a Decimal, but specifying the exponent

fromString : String -> Maybe Decimal

Converts a String to a Maybe Decimal. The string shall be in the format [<sign>]<numbers>[.<numbers>][e<numbers>]

fromFloat : Float -> Maybe Decimal

Converts a Float to a Decimal

To stuff

toString : Decimal -> String

Converts a Decimal to a String

toFloat : Decimal -> Float

Converts a Decimal to a Float

Arithmetic operations

Addition

Substraction

Changes the sign of a Decimal

Multiplication

Fast and dirty division. Don't expect too much precision from this division. Dividing by zero is bad, and Nothing will be returned.

Rounding

Truncates the Decimal to the specified decimal places

round : Int -> Decimal -> Decimal

Rounds the Decimal to the specified decimal places

Comparing

gt : Decimal -> Decimal -> Bool

Greater than

gte : Decimal -> Decimal -> Bool

Greater than or equals

eq : Decimal -> Decimal -> Bool

Equals

neq : Decimal -> Decimal -> Bool

Not equals

lt : Decimal -> Decimal -> Bool

Less than

lte : Decimal -> Decimal -> Bool

Less than or equals

compare : Decimal -> Decimal -> Order

Compares two Decimals

Misc operations

Absolute value (sets the sign as positive)

getDigit : Int -> Decimal -> Int

Gets the specified digit from a Decimal. The digits are: 0 -> units 1 -> tens 2 -> hundreds and so on -1 -> tenths -2 -> hundredths and so on

Common numbers

The number 0

The number 1

The number -1