Overview

This is used to represent a fractional value, or a percentage. The value must be in the range [0, 1].

The factory methods take either a (double) raw fractional real number value, or a ratio:

        Fractional.valueOf(0.141592);
        Fractional.valueOf(4, 7);  // fraction: 4/7

The point is that in application logic, sometimes we have a fractional value as a ratio (like items processed over items total) and we want to represent it in a manner similar to a real number. Basically this saves the steps of doing the conversion, and it has built-in error checking. It can also conveniently convert it to a percentage value for easy display.

Example

        Fractional fractional = Fractional.ratio(4, 7);
        System.out.println(fractional.toString());
        System.out.println(fractional.toPercentage());

would display:

        0.5714
        "57.1%"

Project Overview