on up back w3c Fifth International World Wide Web Conference

Mortgage Applet (2)

    // Convert double to dollars and cents
    static String format(double dollars)
    {   String numString = Double.toString(dollars);
        int dotpos = numString.indexOf(`.');
        if (dotpos < 0)  // Check if whole number
            return numString;
        // Check for excess fraction digits
        else if (dotpos < numString.length() - 2)
            return numString.substring(0, dotpos + 3); // `.'+ 2 digits
        else return numString + "0"; // Assume only 1 fraction digit
    }


Java - An Introductory Language Tutorial (E.A.Johnson)