Converts a decimal price to a fractional price.
#include <imsl.h>
float imsl_f_dollar_fraction (float decimal_dollar, int fraction)
The type double function is imsl_d_dollar_fraction.
float
decimal_dollar (Input)
Dollar price expressed as a decimal
number.
int fraction
(Input)
Denominator of the fractional dollar. fraction must be
positive.
The dollar price expressed as a fraction. The numerator is the decimal part of the return value. If no result can be computed, NaN is returned.
Function imsl_f_dollar_fraction converts a dollar price, expressed as a decimal number, into a dollar price, expressed as a fractional price. If no result can be computed, NaN is returned.
It can be found by solving the following

where idollar is the integer part of the decimal_dollar, and ifrac is the integer part of log(fraction).
In this example, imsl_f_dollar_fraction converts $ 1.25 to $1 1/4.
#include <stdio.h>
#include "imsl.h"
void main()
{
float decimal_dollar = 1.25;
int fraction = 4;
int numerator;
float dollarfrc;
dollarfrc = imsl_f_dollar_fraction (decimal_dollar, fraction);
numerator = dollarfrc*10.-((int)dollarfrc)*10;
printf ("The decimal dollar $1.25 as a fractional dollar = $%i %i/%i.\n",
(int)dollarfrc, numerator, fraction);
}
The decimal dollar $1.25 as a fractional dollar = $1 1/4.
|
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |