4c2098e1c1c7d0f3a5920ab844bbade19b148dee.svn-base 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright Scand LLC http://www.scbr.com To use this component please contact
  3. * info@scbr.com to obtain license
  4. */
  5. /*
  6. * Decimal value (10,000.00) eXcell for dhtmlxGrid (c)Scand LLC 2005
  7. *
  8. *
  9. * The corresponding cell value in XML should be valid number
  10. *
  11. * Samples: <cell>123.01</cell> <cell>1234.09356</cell> <cell>12345</cell>
  12. * <cell>0</cell> <cell>-100</cell>
  13. */
  14. function eXcell_dec(cell) {
  15. this.cell = cell;
  16. this.grid = this.cell.parentNode.grid;
  17. // this.edit = function(){}
  18. this.getValue = function() {
  19. return parseFloat(this.cell.innerHTML.replace(/,/g, ""));
  20. }
  21. this.setValue = function(val) {
  22. var format = "0,000.00";
  23. if (val == "0") {
  24. this.cell.innerHTML = format.replace(/.*(0\.[0]+)/, "$1");
  25. return;
  26. }
  27. var z = format.substr(format.indexOf(".") + 1).length
  28. val = Math.round(val * Math.pow(10, z)).toString();
  29. var out = "";
  30. var cnt = 0;
  31. var fl = false;
  32. for (var i = val.length - 1; i >= 0; i--) {
  33. cnt++;
  34. out = val.charAt(i) + out;
  35. if (!fl && cnt == z) {
  36. out = "." + out;
  37. cnt = 0;
  38. fl = true;
  39. }
  40. if (fl && cnt == 3 && i != 0 && val.charAt(i - 1) != '-') {
  41. out = "," + out;
  42. cnt = 0;
  43. }
  44. }
  45. this.cell.innerHTML = out;
  46. }
  47. }
  48. eXcell_dec.prototype = new eXcell_ed;