Finance functions

View versions (1)

Interface

#include <codecogs/finance/banking/dollar_decimal.h>

using namespace Finance::Banking;

Converts a fractional price to a decimal price.

Fractional to decimal conversion is done using the following equation:

iprice+(fractionalPrice-iprice) \frac{10^{(ifrac+1)}}{fraction}
(1)

where <em>iprice</em> is the integer part of <em>fractionalPrice</em> and <em>ifrac</em> is the integer part of <em>log(fraction)</em>

Example 1

#include <stdio.h>
  #include <codecogs/finance/banking/dollar_decimal.h>
   
  int main()
  {
    double d = Finance::Banking::dollar_decimal(1.3, 8);
    printf("The fractional price $1 3/8 as decimal = %.3f\n", d);
    return 0;
  }

Output

The fractional price $1 3/8 as decimal = 1.375

Parameters

fracPrice
is the price, with the value after the decimal being the numerator of the fraction
frac
the denominator of the fraction

Returns

a double representing the decimal price
GPL Licence — free for non commercial use. See Licence details.

Interactive Calculator

fracPrice
frac
Result