Created
May 14, 2010 12:46
-
-
Save dgmike/401106 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment