locked
Lightswitch HTML - Format an integer with commas? RRS feed

  • Question

  • Hi All,

    I have an Integer value that I want displayed with commas in the thousands place. This is turning out to be way more complicated than it should be :(

    So if I have 1200 I want to see 1,200 on screen.

    I have tried using the postrender function, like this:

        contentItem.dataBind("value", function (value) {

            if (value) {

                $(element).text(value.format("#,##0"));

            }

        })

    Nothing that I put in the format section does anything. I also tried bringing the field in as a Decimal and using the "Format Pattern", same result. Nothing I put in has any effect; I tried N0, N, #,0 and many combinations of that.

    Is there an easy way to do this? I am almost to the point of just formatting in SQL and just bringing the field over as text!

    Thanks, Jeremy


    Jeremy

    Thursday, January 26, 2017 3:17 PM

Answers

  • Hello Jeremy,

    Javascript has a Function number.toLocaleString(); This should be th solution, Keep in mind it's using the lcalization of the Client and Server. Full text can be found here (in the middle of the page).  

    Hope this helps.

    Kind regards

    Thomas

    • Marked as answer by Jeremy Crouch Tuesday, February 7, 2017 2:09 PM
    Monday, February 6, 2017 2:50 PM

All replies

  • Hello Jeremy,

    Javascript has a Function number.toLocaleString(); This should be th solution, Keep in mind it's using the lcalization of the Client and Server. Full text can be found here (in the middle of the page).  

    Hope this helps.

    Kind regards

    Thomas

    • Marked as answer by Jeremy Crouch Tuesday, February 7, 2017 2:09 PM
    Monday, February 6, 2017 2:50 PM
  • Thanks Thomas,I actually ended up Casting my field as INT in SQL, and then still formatting in the _postRender function:

    $(element).text(value.format("n00"));

    I guess value.format does not accept standard formatting strings? The "n00" was the only one I found that worked in this particular case.

    PITA really, as I had to create 9 sets of postRenders to format all of the fields I had. If I ever needed to make a change I have to make it 9 times now :(.

    It would be nice if the "Format Pattern" property on the table's design window actually worked.


    Jeremy

    Tuesday, February 7, 2017 2:15 PM