Chapter 9: Special Functions

dollar_fraction

Converts a decimal price to a fractional price.

Synopsis

#include <imsl.h>

float imsl_f_dollar_fraction (float decimal_dollar, int fraction)

The type double function is imsl_d_dollar_fraction.

Required Arguments

float decimal_dollar   (Input)
Dollar price expressed as a decimal number.

int fraction   (Input)
Denominator of the fractional dollar. fraction must be positive.

Return Value

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.

Description

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

Example

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

}

Output

The decimal dollar $1.25 as a fractional dollar = $1 1/4.


Visual Numerics, Inc.
Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260