Example: Price Conversion - Decimal Dollars

A decimal dollar price, in this case $1.38, is converted to a fractional price.
import com.imsl.finance.*;
import java.text.NumberFormat;

public class dollarfrEx1 {
    public static void main(String args[]) {
        double decimalDollar = 1.38;
        int fraction = 8;
        
        double dollarfrc = Finance.dollarfr(decimalDollar, fraction);
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(2);
        System.out.println("The decimal dollar $1.38 as a fractional dollar = "
        + nf.format(dollarfrc));
    }
}

Output

The decimal dollar $1.38 as a fractional dollar = 1.3
Link to Java source.