Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Thousands separator in javascript when using a function

Hi ... I'm doing a live calculation on a page.  That's working beautifully.  BUT I need to show the result with a thousands separator where applicable.  How do I take the result of one function and then apply it to another?  Here's my code (shortened, otherwise you'll get bored):

 <script>
$(document).ready(function(){
    SSI_CustomGraphicalCheckbox();
   
})
    function SSI_CustomGraphicalCheckbox() {

    //levels;
    var mLhome = [%Listlabel(BUILDPRICEhome,CBCDesignLevelValue(Building_Random1,2,2))%];
    var mLaccom = [%Listlabel(BUILDPRICEaccom,CBCDesignLevelValue(Building_Random1,2,3))%];    
    var pLhome = [%Listlabel(BUILDPRICEhome,CBCDesignLevelValue(Building_Random1,3,2))%];
    var pLhb = [%Listlabel(BUILDPRICEhb,CBCDesignLevelValue(Building_Random1,3,4))%];    

    var mbase = [%CBCDesignLevelText (Building_Random1, 2, 1) %];
    var mhome = SSI_GetValue('BuildingRandom1_mADH_1') * mLhome;
    var maccom = SSI_GetValue('BuildingRandom1_mAccom_1') * mLaccom;    
    var pbase = [%CBCDesignLevelText (Building_Random1, 3, 1) %];
    var phome = SSI_GetValue('BuildingRandom1_pADH_1') * pLhome;    
    var phb = SSI_GetValue('BuildingRandom1_pHB_1') * pLhb;        

     var mprice = mbase;
     var pprice = pbase;

     mprice += mhome;
     mprice += maccom;
     pprice += phome;    
     pprice += phb;    

       
    $('.dynamicPriceM').text(mprice);
    $('.dynamicPriceP').text(pprice);    
}

</script>


And then I use this to show the result:

<span class="dynamicPriceM"></span>
<span class="dynamicPriceP"></span>


So how do I fit the thousands separator thing in there?
asked Dec 14, 2021 by Marion Silver (5,240 points)

1 Answer

0 votes
I used this ... seems to work.  Any downsides?

    strM = mprice.toLocaleString("en-US");
    strP = pprice.toLocaleString("en-US");    
answered Dec 14, 2021 by Marion Silver (5,240 points)
...