Skip to content
FutureBlitz

    Install

    Import std.math.big.decimal

    std.math.big.decimal

    Decimal: a decimal number, over mpdecimal, which never changes once it's made. It holds what it's made from exactly, as 0.1 is, and its arithmetic keeps 28 significant digits, rounded half to even, as Python's decimal does by default, so 1 / 3 is 0.3333333333333333333333333333. A result's exponent stays from -999999 to 999999: past that panics, and below it goes toward 0. Trailing 0s stay, as in 1.50, and ToString shows them, but == doesn't count them, so 1.5 == 1.50. An Int64 on either side of an operator works too. A Decimal stays on its thread, so ToString and Parse are how one goes to another.

    std/math/big/decimal.fb

    Types

    RoundingMode enum

    Public Enum RoundingMode

    How rounding treats what it drops.

    std/math/big/decimal.fb, line 43

    • HALF_EVEN enum member #

      To the nearest, and a half to the even one, as banks round: 2.5 to 2, and 3.5 to 4.

    • HALF_UP enum member #

      To the nearest, and a half away from 0: 2.5 to 3, and -2.5 to -3.

    • HALF_DOWN enum member #

      To the nearest, and a half toward 0: 2.5 to 2, and -2.5 to -2.

    • UP enum member #

      Away from 0: 2.1 to 3, and -2.1 to -3.

    • DOWN enum member #

      Toward 0, dropping the rest: 2.9 to 2, and -2.9 to -2.

    • CEILING enum member #

      Up: 2.1 to 3, and -2.9 to -2.

    • FLOOR enum member #

      Down: 2.9 to 2, and -2.1 to -3.

    Decimal class

    Public Class Decimal Implements Comparable, Hashable, Printable, Numeric

    A decimal number, which holds what it's made from exactly, as 0.1 is, and keeps 28 significant digits in its arithmetic.

    std/math/big/decimal.fb, line 62

    • Public New(value: Int64) constructor #

      The Decimal of value.

    • Public New(value: BigInt) constructor #

      The Decimal of value.

    • Public Static Method Zero(): Decimal static method #

      The number that adding leaves alone: 0.

      Doc from std.core.interfaces.Numeric.Zero.

    • Public Static Method One(): Decimal static method #

      The number that multiplying leaves alone: 1.

      Doc from std.core.interfaces.Numeric.One.

    • @PanicsAtCaller Public Static Method FromDouble(value: Double): Decimal static method #

      The shortest Decimal that reads back as the Double, the digits it prints, so 0.1 is 0.1. A NaN or an infinity panics.

    • Public Static Method Parse(text: String): Decimal? static method #

      The number the text is, exactly: a sign or none, then digits with a "." or not, then an exponent or none, an "E" or "e" and an integer, as "-1.50" and "2.5e-3" are. Other text, NaN and the infinities too, is Null.

    • Public Method ToString(): String method #

      What Python's str gives: its digits with a point where it goes, as in "-1.50", unless its exponent is above 0 or it's quite small, as in "1.5E+3" and "1E-7".

    • Public Method ToPlainString(): String method #

      Its digits with no exponent, as in "1500" and "0.0000001".

    • Public Method ToDouble(): Double method #

      The Double nearest it, ties to even: an infinity past the largest Double, and 0 below the smallest.

    • Public Method ToInt64(): Int64? method #

      It as an Int64, or Null when it isn't a whole number in an Int64's range.

    • Public Method ToBigInt(): BigInt? method #

      It as a BigInt, or Null when it isn't a whole number.

    • Public Property Sign: Int property #

      -1, 0, or 1 as it's below, at, or above 0.

    • Public Property IsInteger: Bool property #

      Whether it's a whole number, as 2.00 and 1E+3 are.

    • Public Method Abs(): Decimal method #

      Its distance from 0: the same Decimal, without its sign.

    • @PanicsAtCaller Public Method Round(places: Int = 0, mode: RoundingMode = RoundingMode.HALF_EVEN): Decimal method #

      It rounded by the mode to the places after the point, or before it when negative: 2.675 is 2.68 to 2 places, and 1234 is 1.2E+3 to -2. Rounding to more digits than 28, or than it has when that's more, panics, and so does a result whose exponent is past 999999 either way, as with Python's quantize.

    • Public Method Truncate(): Decimal method #

      It rounded to a whole number, toward 0, down, or up. One with an exponent above 0 keeps it, as 1.5E+3 does.

    • Public Method Floor(): Decimal method #

      It rounded down to a whole number, toward negative infinity.

    • Public Method Ceiling(): Decimal method #

      It rounded up to a whole number, toward positive infinity.

    • @PanicsAtCaller Public Method Sqrt(): Decimal method #

      Its square root. One below 0 panics.

    • @PanicsAtCaller Public Method Exp(): Decimal method #

      e to its power.

    • @PanicsAtCaller Public Method Ln(): Decimal method #

      Its natural logarithm, and its logarithm in base 10. One that isn't above 0 panics.

    • @PanicsAtCaller Public Method Log10(): Decimal method #

      Its base 10 logarithm. Panics unless it's above 0.

    • @PanicsAtCaller Public Method Pow(exponent: Decimal): Decimal method #

      It to the power, which needn't be whole: 2 to 0.5 is the square root of 2. Anything to 0 is 1, 0 to a power below 0 panics, and so does a number below 0 to one that isn't whole.

    • Public Method Hash(): UInt64 method #

      Its hash, the same for values that are equal.

      Doc from std.core.interfaces.Hashable.Hash.

    • Operator ==(a: Decimal, b: Decimal): Bool operator #

      Whether a and b are equal.

      Doc from std.core.interfaces.Equatable.Operator==.

    • Operator ==(a: Decimal, b: Int64): Bool operator #

      Whether a and b are equal.

    • Operator ==(a: Int64, b: Decimal): Bool operator #

      Whether a and b are equal.

    • Operator <(a: Decimal, b: Decimal): Bool operator #

      Whether a comes before b.

      Doc from std.core.interfaces.Comparable.Operator<.

    • Operator <(a: Decimal, b: Int64): Bool operator #

      Whether a comes before b.

    • Operator <(a: Int64, b: Decimal): Bool operator #

      Whether a comes before b.

    • Operator >(a: Decimal, b: Int64): Bool operator #

      Whether a comes after b.

    • Operator >(a: Int64, b: Decimal): Bool operator #

      Whether a comes after b.

    • Operator <=(a: Decimal, b: Int64): Bool operator #

      Whether a comes before b or is equal to it.

    • Operator <=(a: Int64, b: Decimal): Bool operator #

      Whether a comes before b or is equal to it.

    • Operator >=(a: Decimal, b: Int64): Bool operator #

      Whether a comes after b or is equal to it.

    • Operator >=(a: Int64, b: Decimal): Bool operator #

      Whether a comes after b or is equal to it.

    • @PanicsAtCaller Operator +(a: Decimal, b: Decimal): Decimal operator #

      a and b added up.

      Doc from std.core.interfaces.Numeric.Operator+.

    • @PanicsAtCaller Operator +(a: Decimal, b: Int64): Decimal operator #

      a plus b.

    • @PanicsAtCaller Operator +(a: Int64, b: Decimal): Decimal operator #

      a plus b.

    • @PanicsAtCaller Operator -(a: Decimal, b: Decimal): Decimal operator #

      b taken away from a.

      Doc from std.core.interfaces.Numeric.Operator-.

    • @PanicsAtCaller Operator -(a: Decimal, b: Int64): Decimal operator #

      a minus b.

    • @PanicsAtCaller Operator -(a: Int64, b: Decimal): Decimal operator #

      a minus b.

    • @PanicsAtCaller Operator *(a: Decimal, b: Decimal): Decimal operator #

      a and b multiplied together.

      Doc from std.core.interfaces.Numeric.Operator*.

    • @PanicsAtCaller Operator *(a: Decimal, b: Int64): Decimal operator #

      a times b.

    • @PanicsAtCaller Operator *(a: Int64, b: Decimal): Decimal operator #

      a times b.

    • @PanicsAtCaller Operator /(a: Decimal, b: Decimal): Decimal operator #

      a divided by b.

      Doc from std.core.interfaces.Numeric.Operator/.

    • @PanicsAtCaller Operator /(a: Decimal, b: Int64): Decimal operator #

      a divided by b.

    • @PanicsAtCaller Operator /(a: Int64, b: Decimal): Decimal operator #

      a divided by b.

    • @PanicsAtCaller Operator %(a: Decimal, b: Decimal): Decimal operator #

      What's left of a / b with its quotient rounded toward 0, so it has a's sign, exactly. A quotient of more digits than 28, or than a or b has when that's more, panics.

    • @PanicsAtCaller Operator %(a: Decimal, b: Int64): Decimal operator #

      What's left of a / b with its quotient rounded toward 0, so it has a's sign, exactly. A quotient of more digits than 28, or than a or b has when that's more, panics.

    • @PanicsAtCaller Operator %(a: Int64, b: Decimal): Decimal operator #

      What's left of a / b with its quotient rounded toward 0, so it has a's sign, exactly. A quotient of more digits than 28, or than a or b has when that's more, panics.

    • @PanicsAtCaller Operator **(a: Decimal, b: Int64): Decimal operator #

      To a whole power: anything to 0 is 1, and 0 to a power below 0 panics.

    • Operator -(a: Decimal): Decimal operator #

      a negated.

    Report an issue with this page or with FutureBlitz on GitHub.