dollarDecimal¶
Converts a fractional price to a decimal price.
Synopsis¶
dollarDecimal (fractionalDollar, fraction)
Required Arguments¶
- float
fractionalDollar
(Input) - Whole number of dollars plus the numerator, as the fractional part.
- int
fraction
(Input) - Denominator of the fractional dollar.
fraction
must be positive.
Return Value¶
The dollar price expressed as a decimal number. The dollar price is the whole number part of fractional-dollar plus its decimal part divided by fraction. If no result can be computed, NaN is returned.
Description¶
Function dollarDecimal
converts a dollar price, expressed as a fraction,
into a dollar price, expressed as a decimal number.
It is computed using the following:
\[\mathit{idollar} +
\left[\mathit{fractionalDollar} - \mathit{idollar}\right] *
\frac{10^{(\mathrm{ifrac}+1)}}{\mathit{fraction}}\]
where idollar is the integer part of fractionalDollar, and ifrac is the integer part of log(fraction).
Example¶
In this example, dollarDecimal
converts $1 1/4 to $1.25.
from __future__ import print_function
from numpy import *
from pyimsl.math.dollarDecimal import dollarDecimal
fractional_dollar = 1.1
fraction = 4
dollardec = dollarDecimal(fractional_dollar, fraction)
print("The fractional dollar $1 1/4 = $%.2f." % (dollardec))
Output¶
The fractional dollar $1 1/4 = $1.25.