3/12/08

Ben:

Thanks. I have not been in Los Angeles since 1986 when I worked on the second Bradley for Governor race. I figured out the percentage issue in terms of showing the percent value (e.g. 76%) and having it sort correctly with no leading zeros for Exhibit. The real challenge was getting the percentage numbers to sort correctly. This will not work with the freestanding Timeplot, but may work someday, when the Timeplot component is finished for Exhibit and you do a Timeplot as part of Exhibit. I have not had time to test it with the Beta component of Exhibit.

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>

    <script type="text/javascript">

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

function addPercent(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 use the following structure:

<div ex:role="view"
                    ex:viewClass="Tabular"
ex:label="Table View of School District Total Revenue" ex:columns=".SchoolDistrict, .InstCity, .CountyName, .IUName, .TOTALREVA LL, .APERCENTFEDSCALE, .APERCENTSTATESCALE, .APERCENTLOCALSCALE" ex:columnLabels="School District, City, County, Intermediate Unit, Total Revenue, &#37; From Fed., &#37; From PA, &#37; From Local" ex:formats="currency {decimal-digits :0} number {decimal-digits :2}" ex:columnFormats="list, list, list, list, currency, number, number, number"
                 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 for the currency. For the percentage number formatting use 00.000 (with one extra trailing 0, in other words, if you want to have a percentage with two numbers to the right of the decimal that you want to show in Exhibit, have 3 zeros to the right of the decimal in the formatting.

--
David L. Cohen


On Mar 11, 2008, at 11:20 PM, Welsh, Ben wrote:

Holy moly! Thanks David! That’s a huge help. If you’re ever in the vicinity of downtown Los Angeles, the beers are all on me.



I wonder if I can apply the same logic somehow to Timeplot…and whether I could get the same thing working for percentage values (ex. 76%).



Benj.



From: [EMAIL PROTECTED] [mailto:general- [EMAIL PROTECTED] On Behalf Of dlcohen1
Sent: Tuesday, March 11, 2008 8:07 PM
To: General List
Subject: Re: Currency formatting in Exhibit



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, .APERCEN TSTATESCALE, .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

General@simile.mit.edu

http://simile.mit.edu/mailman/listinfo/general



_______________________________________________
General mailing list
General@simile.mit.edu
http://simile.mit.edu/mailman/listinfo/general

_______________________________________________
General mailing list
General@simile.mit.edu
http://simile.mit.edu/mailman/listinfo/general

Reply via email to