Graphics

 View Only
  • 1.  Adding Commas to Integers

    Posted 02-11-2013 21:11
    We pull our elections data from DataLinq via an xml feed, and the provider strips conventional formatting from it, (i.e., 123456789 instead of 123,456,789).

    I would like to add that back in. Currently, it's just placed as text, so I would need to convert that number from text to an integer, then reformat the integer is my guess. I could also be way off.

    If you've got some advice, thank you in advance! I'd love to see if someone already has this one figured out.


  • 2.  RE: Adding Commas to Integers

    Posted 02-11-2013 21:41
    Hi Dan,

    You could use scripting to change the format.

    In the OnOnline scripting event you can add this code:

    dim TxtObj as xpTextObject

    dim Temp as long

    self.getObjectByName("Text1", TxtObj)

    Temp = clng(TxtObj.Text)

    TxtObj.Text = String.Format("{0:0,0}",Temp)

    This will get the value from the textfield called Text1, convert it into a long integer and afterwards puts it back in the same textfield but with the correct formatting.

    You do would need to check if it's using commas.

    Greets,

    Kenneth

    #XPression


  • 3.  RE: Adding Commas to Integers

    Posted 02-12-2013 16:56
    Could I do this on the actual text object? Or would I need to do this at the scene level?

    For example, I'm currently running a script on the timestamp data that comes from the same source, converting the xml time stamp to a text format that works.

    I'm thinking something along the lines of:

    dim temp as long

    temp = text

    text = String.Format("{0:0,0}", temp)


    Just in the actual text file.

    EDIT: Gave it a shot. the " in the string format make XPression look for a text object within it, and it spits out the unformatted number. If I remove the " from the string format, I get syntax errors.

    Thoughts?

    #XPression


  • 4.  RE: Adding Commas to Integers

    Posted 02-12-2013 17:07
    Got this one step further than my last post.

    Here is the script I am currently running on the object (not the scene):

    dim temp as Integer

    dim form as string

    temp = text

    form = temp.ToString("N")

    text = form & Environment.NewLine & "Votes"



    When the input is 123456789, the output becomes

    123,456,789.00

    Votes


    Which is pretty dang close. However, As most of us are aware, there is no need for a decimal point when it comes to whole values. Is there a custom numeric string format I can create? Or another standard string format I can use that will not include decimals?

    #XPression


  • 5.  RE: Adding Commas to Integers

    Posted 02-12-2013 19:39
    Okay, got the fix. I needed to create a custom numeric string format. I just needed to find the format that worked for the output I desired (amazing what a lunch break will do for you). It's always the simple ones that get you.

    Here's the new code:

    dim temp as Integer

    dim form as string

    temp = text

    form = temp.ToString("#,#")

    text = form & Environment.NewLine & "Votes"

    Input 123456789 =

    123,456,789

    Votes

    Input 1234 =

    1,234

    Votes


    Hopefully this helps someone down the road.

    #XPression


  • 6.  RE: Adding Commas to Integers

    Posted 02-13-2013 08:52
    Using VBscript's FormatNumber function can be quite handy too:

    [FormatNumber(Expression [,NumDigitsAfterDecimal [,IncludeLeadingDigit [,UseParensForNegativeNumbers [,GroupDigits]]]])


    Other related functions are:
    FormatCurrency

    FormatDateTime

    FormatNumber

    FormatPercent

    Since this functions are based on number formatting settings in Windows, make sure correct settings are used on target system.

    If your DataLinq source is an XML or JSON or TXT pre-processing with PowerShell can be more efficient than running scripts on scenes/elements. On Gist below you can find some sample code for a stock ticker data with pre-formatted up/down symbols:

    sample PowerShell script

    Note that in order to use invoke-RestMethod Powershell 3 is needed.

    #XPression