3/11/08

Ben:

I recently figured out the answer to the currency issue. For me what works is:

In the <head>

<script type="text/javascript">

     Exhibit.Formatter._CurrencyFormatter.prototype.formatText =
     function(value) {
       var number;
       if (this._decimalDigits == -1) {
         number = value.toString();
       }
       else {
         number = new Number(value).toFixed(this._decimalDigits);
       }
       number = addCommas(number);
       return number;
     };

function addCommas(nStr)
{
   nStr += '';
   x = nStr.split('.');
   x1 = x[0];
   x2 = x.length > 1 ? '.' + x[1] : '';
   var rgx = /(\d+)(\d{3})/g;
   while (rgx.test(x1)) {
     x1 = x1.replace(rgx, '$1' + ',' + '$2');
   }
   return "$" + x1 + x2;
}

   </script>

For the view I use the following structure:

  <div ex:role="view"
                    ex:viewClass="Tabular"
ex:label="Table View of School District &#37 Revenue From Pennsylvania" ex:columns=".SchoolDistrict, .InstCity, .CountyName, .IUName, .APERCENTS TATESCALE, .TSTREVALL" ex:columnLabels="School District, City, County, Intermediate Unit, &#37; of Revenue From PA, Amount of PA Revenue"
                    ex:formats="currency {decimal-digits :0}"
ex:columnFormats="list, list, list, list, number, currency"
                 ex:sortColumn="0"
                    ex:sortAscending="true"
                    ></div>


I use EditGrid to populate my Exhibit and have the currency numbers formatted as 00000 (with one extra leading 0, in other words if my largest number is 12345 I have 6 zeros for the formatting. Change the {decimal-digits :0} to {decimal-digits :2} if you want to show $12345.67.

--
David L. Cohen

On Mar 11, 2008, at 9:47 PM, Welsh, Ben wrote:

Hello listers,



First time post here. Please indulge any breaches of etiquette.



I’ve searched the list archive and reviewed the wiki docs I could find, but I’m not coming across a suitable solution for formatting currency values in Exhibit’s tabular view. I’ve issued code like this…



                <div ex:role="view"

                    ex:viewClass="Tabular"

ex:columns=".label, .Revenue, .Return, .Percent, .Years"

ex:columnLabels="Charity, Total Revenue, Total Return, Percent Return, Years Reported"

ex:columnFormats="list, currency {symbol :'$M';}, currency, number, list"

                    >

                </div>



…to no effect. I see a previous post from a couple months back that touched on some problems getting currency support to work, but couldn’t find a thorough response.



I’m curious what experiences other people have had trying to format currency values. Is it something you’ve got working, and I’m just making errors on my end? Or is there some trick I don’t have down?



While I’m at it, is it possible with Simile’s formatting system to add commas that delimit out numeric values when they reach into the millions and thousands (Ex. $100,000).



Thanks,



Ben Welsh

_______________________________________________
General mailing list
[email protected]
http://simile.mit.edu/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://simile.mit.edu/mailman/listinfo/general

Reply via email to