You are here: irt.org | About | Feedback | 5217 [ previous next ]
Feedback on:
irt.org FAQ Knowledge Base Q8
Sent by
Heron Anzures on Friday February 22, 2008 at 14:10:52
Worth:
Very worth reading
Length:
Just right
Technical:
Just right
Comments:
This solution also works with decimals and negatives.
<script type="text/javascript">
function format(number)
{
var text = new String(number);
var negative = text.charAt(0) == '-';
while(true)
{
var i = text.indexOf(",");
if(i == -1)
i = text.indexOf(".");
if(i == -1)
i = text.length;
if(i > 3 && !negative || i > 4)
text = text.substring(0,i-3)+","+text.substring(i-3);
else
return text;
}
}
document.write(format(-123456789) + "<br/>");
document.write(format(1233456.13) + "<br/>");
</script>
Other feedback on 'irt.org FAQ Knowledge Base Q8' - show all