dgmike
5/14/2010 - 12:46 PM

number_fixIt.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Integers</title>
</head>
<body>
    <script type="text/javascript">
    
Number.prototype.fixIt = function(){
    var numbers = this.toFixed(2).split('.')
    var integer = numbers[0]
    var decimal = numbers[1]
    var numbers = integer.split('')
    var saida = ''
    for (i=numbers.length-1;i>=0;i--) {
        if (!(i%3)) {
            saida = '.' + saida
        }
        saida = numbers[i] + saida
    }
    // Removendo o ponto extra que pode ficar
    saida = saida.replace(/\.$/, '')
    return saida + ',' + decimal
}
    document.write((1234.500).fixIt())
    </script>
</body>
</html>