Import std.math.big.decimal
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.
Examples
Local tenth = Decimal.Parse("0.1") ?? Decimal(0)
Expect("{tenth + tenth + tenth}" == "0.3")
Expect("{Decimal(1) / Decimal(3)}" == "0.3333333333333333333333333333")
Local price = Decimal.Parse("2.675") ?? Decimal(0)
Expect(price.Round(2).ToString() == "2.68")
Expect(Decimal.Parse("1.50") == Decimal.Parse("1.5"))std/math/big/decimal.fb, line 75
-
The Decimal of
value. -
The Decimal of
value. -
The zero Decimal, 0, which adding leaves alone.
-
The Decimal 1, which multiplying leaves alone.
-
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.
-
The number the
textis, 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. -
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".
-
Its digits with no exponent, as in "1500" and "0.0000001".
-
The Double nearest it, ties to even: an infinity past the largest Double, and 0 below the smallest.
-
It as an Int64, or Null when it isn't a whole number in an Int64's range.
-
It as a BigInt, or Null when it isn't a whole number.
-
-1, 0, or 1 as it's below, at, or above 0.
-
Whether it's a whole number, as 2.00 and 1E+3 are.
-
Its distance from 0: the same Decimal, without its sign.
-
@PanicsAtCaller Public Method Round(places: Int = 0, mode: RoundingMode = RoundingMode.HALF_EVEN): Decimalmethod #It rounded by the
modeto theplacesafter the point, or before it when negative: 2.675 is 2.68 to 2places, 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. -
It rounded to a whole number, toward 0, down, or up. One with an exponent above 0 keeps it, as 1.5E+3 does.
-
It rounded down to a whole number, toward negative infinity.
-
It rounded up to a whole number, toward positive infinity.
-
Its square root. One below 0 panics.
-
e to its power.
-
Its natural logarithm. Panics unless it's above 0.
-
Its base 10 logarithm. Panics unless it's above 0.
-
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.
-
A hash of its value, the same for Decimals that are equal, as 1.5 and 1.50 are.
-
Whether
aandbare the same number, whatever trailing 0s either has. -
Whether
aandbare equal. -
Whether
aandbare equal. -
Whether
ais less thanb. -
Whether
acomes beforeb. -
Whether
acomes beforeb. -
Whether
acomes afterb. -
Whether
acomes afterb. -
Whether
acomes beforebor is equal to it. -
Whether
acomes beforebor is equal to it. -
Whether
acomes afterbor is equal to it. -
Whether
acomes afterbor is equal to it. -
aplusb, to 28 significant digits. Panics when the result's exponent is past 999999. -
aplusb. -
aplusb. -
aminusb, to 28 significant digits. Panics when the result's exponent is past 999999. -
aminusb. -
aminusb. -
atimesb, to 28 significant digits. Panics when the result's exponent is past 999999. -
atimesb. -
atimesb. -
adivided byb, to 28 significant digits. Abof 0 panics. -
adivided byb. -
adivided byb. -
What's left of
a/bwith its quotient rounded toward 0, so it hasa's sign, exactly. A quotient of more digits than 28, or thanaorbhas when that's more, panics. -
What's left of
a/bwith its quotient rounded toward 0, so it hasa's sign, exactly. A quotient of more digits than 28, or thanaorbhas when that's more, panics. -
What's left of
a/bwith its quotient rounded toward 0, so it hasa's sign, exactly. A quotient of more digits than 28, or thanaorbhas when that's more, panics. -
To a whole power: anything to 0 is 1, and 0 to a power below 0 panics.
-
anegated.
Report an issue with this page or with FutureBlitz on GitHub.