function currency(num) {
    num = num.replace(/[\$\,\ ]/g, "");
    num=eval(num)
    the_string = "" + Math.abs((Math.round(num*100)/100));

    if (num == Math.floor(num)) {
        the_string += ".00";
    } else {
        var cents = num + "";
        cents = cents.replace(/.*\./, "");
        if(cents.length > 2) {
            cents = cents.substr(0,2);
        } else if(cents.length < 2) {
            cents += "0";
        }
        num = num + "";
        the_string = num.replace(/[0-9]+$/, cents);
    }

    while(the_string.search(/\d\d\d\d[\.,]/) != -1) {
        the_string = the_string.replace(/(\d)(\d\d\d[\.,])/, "$1,$2");
    }

    if (num<0) {
        the_string = "(" + the_string + ")";
    }

    return "$" + the_string;
}