|
4 | 4 | [](https://ci.appveyor.com/project/omus/fixedpointdecimals-jl)
|
5 | 5 | [](https://coveralls.io/github/JuliaMath/FixedPointDecimals.jl?branch=master)
|
6 | 6 | [](https://codecov.io/github/JuliaMath/FixedPointDecimals.jl?branch=master)
|
| 7 | + |
| 8 | +Provides the fixed-point decimal type `FixedDecimal` allowing for exact representations of |
| 9 | +decimal numbers. These numbers are useful in financial calculations where interactions |
| 10 | +between decimal numbers are required to be exact. |
| 11 | + |
| 12 | +This library defines the type `FixedDecimal{T <: Integer, f}` as a subtype of `Real`. The |
| 13 | +parameter `T` is the underlying machine representation and `f` is the number of decimal |
| 14 | +places which can be stored. |
| 15 | + |
| 16 | +For example, `FixedDecimal{Int8, 2}` allows you to a decimal number with up to 2 fractional |
| 17 | +digits. All `FixedDecimal{Int8, 2}` numbers `x` must satisfy |
| 18 | + |
| 19 | +``` |
| 20 | +-1.28 = -128/10² ≤ x ≤ 127/10² = 1.27 |
| 21 | +``` |
| 22 | + |
| 23 | +because the range of `Int8` is from -128 to 127. |
| 24 | + |
| 25 | +In general `FixedDecimal{T <: Integer, f}` numbers `y` must satisfy: |
| 26 | + |
| 27 | +``` |
| 28 | +typemin(T)/10ᶠ ≤ y ≤ typemax(T)/10ᶠ |
| 29 | +``` |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +```julia |
| 34 | +julia> using FixedPointDecimals |
| 35 | + |
| 36 | +julia> 2.2 / 10 |
| 37 | +0.22000000000000003 |
| 38 | + |
| 39 | +julia> FixedDecimal{Int,2}(2.2) / 10 |
| 40 | +FixedDecimal{Int64,2}(0.22) |
| 41 | + |
| 42 | +julia> 0.1 + 0.2 |
| 43 | +0.30000000000000004 |
| 44 | + |
| 45 | +julia> FixedDecimal{Int,1}(0.1) + FixedDecimal{Int,1}(0.2) |
| 46 | +FixedDecimal{Int64,1}(0.3) |
| 47 | +``` |
0 commit comments