LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Thousands Separator

    Employee
    Posted 09-06-2011 13:35

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ehoeger

    Is there a simple way to take an integer and convert it to a string with commas as the thousands separator? For example: the input int value is 13904554; the output string value is 13,904,554


  • 2.  RE: Thousands Separator

    Employee
    Posted 09-07-2011 02:18

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hi,

    You would normally use the format operator to perform string formatting on an int. Someone can correct me if I'm wrong, but I can't see any way to do what you want with the format operator.

    The easiest way that I can see to do this in BRAINscript is using something like the following, for an input integer field "x":

    formattedInt = ""
    remainder = x
    while remainder > 1000 {
        formattedInt  = "," + remainder % 1000 + formattedInt 
        remainder = remainder.div(1000)
    }
    formattedInt  = remainder + formattedInt 
    emit formattedInt


  • 3.  RE: Thousands Separator

    Employee
    Posted 09-07-2011 16:01

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ehoeger

    Sweet solution - very clever