[ka-Map-users] Re: thousands delimiter in scale drop down

János Gonzales janos.gonzales at gmail.com
Thu Apr 5 15:20:18 EDT 2007


Hello,
It looks like there's a function called formatNumber located in
scalebar.js that puts thousands delimiters in numbers.  I tried
calling this function from starUp.js  in the part where the scale
options are added to the html page (approx. line 195) , like so:

oSelect.options[j++] = new
Option("1:"+formatNumber(scales[i]),scales[i],false,false);

This did not work however as formatNumber is part of the ScaleBar
prototype and i'm not sure how to call it.  So I just copied the
formatNumber function into startUp.js  and then I got comma delimited
thousands in the scale dropdown.


  function formatNumber(aNumber, numDecimals) {
        numDecimals = (numDecimals) ? numDecimals : 0;
        var formattedInteger = '' + Math.round(aNumber);
        var thousandsPattern = /(-?[0-9]+)([0-9]{3})/;
        while(thousandsPattern.test(formattedInteger)) {
            formattedInteger =
formattedInteger.replace(thousandsPattern, '$1,$2');
        }
        if(numDecimals > 0) {
            var formattedDecimal = Math.floor(Math.pow(10,
numDecimals) * (aNumber - Math.round(aNumber)));
            if(formattedDecimal == 0) {
                return formattedInteger;
            }
            else {
                return formattedInteger + '.' + formattedDecimal;
            }
        }
        else {
            return formattedInteger;
        }
    };





On 3/28/07, János Gonzales <janos.gonzales at gmail.com> wrote:
> Hello,
>
> I am working with some large scales in my ka-maps and the drop down
> scale bar is getting rather difficult to read (  1:100000000  etc...)
>  I think it would be good if the thousands were separated with commas
> i.e. 1:10,000,000    (or periods, depending on the country).
>
> How can I do this? Which file do I need to change?
>
> Thanks



More information about the ka-Map-users mailing list