Fixed point type
To use this package, run the following command in your project's root directory:
Put the following dependency into your project's dependences section:
Defines a fixed point type.
A fixed point number is a number with a fixed number of decimal places. The number of decimal places never varies, unlike floating point types, where the number of decimal places varies depending on the value.
Fixed point values are used wherever fractions are needed, but floating point values are undesirable or impractical, eg currencies.
Fixed point values are precise (no rounding issues) and are integral in behaviour (division and modulo work the same as they do for integers).
See doc.html for reference documentation.
jaypha.fixed into your project. Instantiate with the desired scale.
auto v = Fixed!2(23); // Creates a value with 2 decimal places.
Fixed implements all the arithmetic, comparison and assignment operators, as well as casting to long and double types.
In addition the following methods are defined
pure nothrow auto conv(uint newScale)()
Converts to a different number of decimal places.
@property string asString()
Convert to a string. Includes the full number of decimal places.
fix3 are defined as aliases of
fix3 value = 21.44; value += 12; assert(value.asString == "33.440");
Distributed under the Boost License.
- Registered by Jason den Dulk
- 1.0.1 released 8 years ago
- Copyright 2014, Jaypha