function NumFormatter() {
    this.decimal_regex = /(\d+)\.(\d+)/;

    this.comma_format = function(int_num) {
        var arg_type = (typeof int_num); //xxx
        if (arg_type == "string") {
            var num_str = int_num;
        } else if (arg_type == "number") {
            var num_str = int_num + "";
        }

        var len = num_str.length;
        var r = "";
        var j = 1;

        var decimal_point_index = num_str.indexOf(".");
        var starting_point_index = len - decimal_point_index - 1;

        for (var i = len - 1; i >= 0; i--) {
            var char_candidate = num_str.charAt(i);
            if (j % 3 == 0) {
                if (i != 0) r = "," + char_candidate + r;
                else r = char_candidate + r;
            } else {
                r = char_candidate + r;
            } // else
            if (decimal_point_index == -1) {
                // doesn't have decimal
                j++;
            } else {
                // deal with decimal
                if ((len - 1 - i) > starting_point_index) {
                    j++;
                }
            }
        } // for
        return r;
    };

    this.format_decimal = function(float_num, decimal_places) {
        if (float_num == "Undefined") {
            return float_num;
        } else if (float_num == "N/A") {
            return "---";
        } else {
            var decimal_place_num = Math.pow(10, decimal_places);

            var r_str = String(Math.round(float_num * decimal_place_num) / decimal_place_num);
            var r_reg = this.decimal_regex.exec(r_str);
            var padded_zeros = decimal_places;
            // r_reg is null if float_num doesn't have a decimal point in it. like 1 instead of 1.0
            if (r_reg != null) {
                padded_zeros -= r_reg[2].length;
            } else {
                r_str += ".";
            }

            for (var i = 0; i < padded_zeros; i++) {
                r_str += "0";
            }
            return r_str;
        }
    };
}

