fixed 1.0.1

Fixed point type


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

Fixed

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).

Documentation

See doc.html for reference documentation.

Usage

Import jaypha.fixed into your project. Instantiate with the desired scale.

Example:

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.

fix1, fix2 and fix3 are defined as aliases of Fixed!1, Fixed!2 and Fixed!3 respectively.

Example

fix3 value = 21.44;
value += 12;
assert(value.asString == "33.440");

License

Distributed under the Boost License.

Contact

[email protected]

Todo

Authors:
  • Jason den Dulk
Dependencies:
none
Versions:
1.1.0 2021-Jul-11
1.0.5 2016-Aug-24
1.0.4 2016-Apr-09
1.0.3 2016-Mar-27
1.0.2 2015-Aug-18
Show all 7 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 221 downloads total

Score:
0.6
Short URL:
fixed.dub.pm