Errore di sintassi (mio):
tot = tot.toString().replace(/\./, ",");

Prova cosi` e fammi sapere.