A thousands renderer for the Ext Grid control

Sep 17 2007

I needed to format large numbers by adding thousand separators in my Ext.js powered grid—and, as I couldn’t find one anywhere else, I wrote my own quick implementation. Here’s what I came up with:

  1. function add_thousands_separator(input) {
  2. var s = input.toString(), l = s.length, o = '';
  3. while (l > 3) {
  4. var c = s.substr(l - 3, 3);
  5. o = ',' + c + o;
  6. s = s.replace(c, '');
  7. l -= 3;
  8. }
  9. o = s + o;
  10. return o;
  11. }
  12.  
  13. Download this code: /code/renderer.txt

Hopefully someone else might find this useful too.

Filed under: Javascript.

Technorati tags:

Digg this article

Bookmark this article with del.icio.us

Previously: Refresh Cambridge 09/05 - Flex, Usability, and Drupal

Next: Porting Active Record to CodeIgniter


Comments