FixedDecimal::Value
Conversions to and from the arbitrary-precision types in big, which
needs libgmp. Opt in with require "fixed_decimal/big".
Instance methods
Divides, rounding half-to-even. Raises DivisionByZeroError for a zero
divisor.
Divides, rounding half-to-even. Raises DivisionByZeroError for a zero
divisor.
Compares exact values, even across different types and fraction bits.
Compares exact values, even across different types and fraction bits.
Formats like sprintf("%*.*f", width, decimal, value).
- width is the minimum field width; a negative width left-justifies.
- decimal is the exact number of fraction digits, rounded
half-to-even;
nilmeans the shortest form, as in#to_s, and0omits the decimal point. - padding fills the field. A
'0'goes between the sign and the digits, as withsprintf's0flag, and becomes a space when left-justifying.
Fixed(16).new("-3.25").format(8, 3, '0') # => "-003.250"
Formats like sprintf("%*.*f", width, decimal, value).
- width is the minimum field width; a negative width left-justifies.
- decimal is the exact number of fraction digits, rounded
half-to-even;
nilmeans the shortest form, as in#to_s, and0omits the decimal point. - padding fills the field. A
'0'goes between the sign and the digits, as withsprintf's0flag, and becomes a space when left-justifying.
Fixed(16).new("-3.25").format(8, 3, '0') # => "-003.250"
Formats using a sprintf-style spec: %[flags][width][.precision][f].
- The leading
%is optional. - Flags:
-left-justifies,+always shows a sign, a space shows a space for non-negative values,0pads with zeros and#always shows the decimal point. - With the
f(orF) conversion the precision defaults to 6, as insprintf; without it the shortest form is used.
Raises ArgumentError for an invalid spec.
Fixed(16).new("2.5").format("%+08.2f") # => "+0002.50"
Fixed(16).new("2.5").format("-6") # => "2.5 "
Formats using a sprintf-style spec: %[flags][width][.precision][f].
- The leading
%is optional. - Flags:
-left-justifies,+always shows a sign, a space shows a space for non-negative values,0pads with zeros and#always shows the decimal point. - With the
f(orF) conversion the precision defaults to 6, as insprintf; without it the shortest form is used.
Raises ArgumentError for an invalid spec.
Fixed(16).new("2.5").format("%+08.2f") # => "+0002.50"
Fixed(16).new("2.5").format("-6") # => "2.5 "
Rounds to an integral value using mode. Raises OverflowError if the
result is out of range.
The nearest Float32, rounding half-to-even. Raises OverflowError if
it rounds beyond Float32::MAX.
Truncates toward zero and converts to Int128. Raises
OverflowError if the integer part is out of range.
Truncates toward zero and converts to Int128, wrapping
around on overflow like Int#to_i128!.
Truncates toward zero and converts to Int128, or returns
nil if the integer part is out of range.
Truncates toward zero and converts to Int16. Raises
OverflowError if the integer part is out of range.
Truncates toward zero and converts to Int16, wrapping
around on overflow like Int#to_i16!.
Truncates toward zero and converts to Int16, or returns
nil if the integer part is out of range.
Truncates toward zero and converts to Int32. Raises
OverflowError if the integer part is out of range.
Truncates toward zero and converts to Int32, wrapping
around on overflow like Int#to_i32!.
Truncates toward zero and converts to Int32, or returns
nil if the integer part is out of range.
Truncates toward zero and converts to Int64. Raises
OverflowError if the integer part is out of range.
Truncates toward zero and converts to Int64, wrapping
around on overflow like Int#to_i64!.
Truncates toward zero and converts to Int64, or returns
nil if the integer part is out of range.
Truncates toward zero and converts to Int8. Raises
OverflowError if the integer part is out of range.
Truncates toward zero and converts to Int8, wrapping
around on overflow like Int#to_i8!.
Truncates toward zero and converts to Int8, or returns
nil if the integer part is out of range.
Writes the shortest decimal representation that parses back to exactly
this value. It always has a fraction digit ("1.0") unless there are
no fraction bits ("1").
Truncates toward zero and converts to UInt128. Raises
OverflowError if the integer part is out of range.
Truncates toward zero and converts to UInt128, wrapping
around on overflow like Int#to_u128!.
Truncates toward zero and converts to UInt128, or returns
nil if the integer part is out of range.
Truncates toward zero and converts to UInt16. Raises
OverflowError if the integer part is out of range.
Truncates toward zero and converts to UInt16, wrapping
around on overflow like Int#to_u16!.
Truncates toward zero and converts to UInt16, or returns
nil if the integer part is out of range.
Truncates toward zero and converts to UInt32. Raises
OverflowError if the integer part is out of range.
Truncates toward zero and converts to UInt32, wrapping
around on overflow like Int#to_u32!.
Truncates toward zero and converts to UInt32, or returns
nil if the integer part is out of range.
Truncates toward zero and converts to UInt64. Raises
OverflowError if the integer part is out of range.
Truncates toward zero and converts to UInt64, wrapping
around on overflow like Int#to_u64!.
Truncates toward zero and converts to UInt64, or returns
nil if the integer part is out of range.
Truncates toward zero and converts to UInt8. Raises
OverflowError if the integer part is out of range.
Truncates toward zero and converts to UInt8, wrapping
around on overflow like Int#to_u8!.
Truncates toward zero and converts to UInt8, or returns
nil if the integer part is out of range.