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.  Number Formatting

    Employee
    Posted 01-20-2015 20:16

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

    Originally posted by: gihans

    Hi ,

    Can someone advise on how to format numbers ? for example, format 12354.24 to 12,354.24

    Thanks,
    Gihan


  • 2.  RE: Number Formatting

    Employee
    Posted 01-28-2015 20:20

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

    Originally posted by: myrnab

    hi,
    I have the same question as gihans, i.e. i want to be able to format numbers as well as amounts to have the dollar symbol before publishing the report (eg. excel). Can someone help please?


  • 3.  RE: Number Formatting

    Employee
    Posted 01-28-2015 21:01

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

    Originally posted by: ejones

    Thanks for this second question, it helped me realize what the best answer is for the first question.

    The best thing to do for the best looking reports is to use software that has formatting beautiful reports as its purpose. LAE is very good for pulling the data together for one of these other reporting systems.

    So for Excel, the best thing to do is learn how to use the "Output Excel" node. On the Optional tab there is a parameter named TemplateInputFile. This is where you put the name of a spreadsheet that is already formatted the way you want the report to be formatted. In that spreadsheet you preformat the columns to have dollar signs and commas as you want them.

    I'm also familiar with Tableau and I'm sure other similar packages have the same feature where you configure the formatting of the data for the reports being produced from it. Using LAE you pull the data together and do your analysis, then feed the results to a reporting tool and let it format it.

    But, I have done the formatting in BRAINscript and it isn't easy. You have to write many lines of code and make certain assumptions about what the format will be and code it that way. Note that it is generally good practice to keep your formatting code separate from the logic that pulls the data together and does analysis because this way when you are working on the analysis the reporting isn't being touched. And when adjusting the reporting, you are staying away from the analysis logic.

    In the following code, the number that is to be formatted is in a field named 'f'. The values always more than -1 billiion and less than 1 billion. There will always be two digits after the decimal which is indicated by a period and the thousands separator is indicated by a comma. There is a large part of this world that tends to flip the meaning of the comma and period and if this is done, an additional step would need to be done to replace the period produced by the format() function with a comma.

    The code begins by initializing s and then builds it in pieces. It then outputs the result in a string field named s. I'm sure this can be improved.
    if 'f' < 0
    	then s = "-"
    	else s = ""
    w = abs('f').floor().long()
    p = abs('f') - w
    if w > 1000000 then {
    	s = s + w.div(1000000).str() + ","
    	w = w.mod(1000000)
    }
    if w > 1000 then {
    	s = s + w.div(1000).str() + ","
    	w = w.mod(1000)
    }
    s = s + w.str() + format("%.02f",p).substr(1)
    emit s


  • 4.  RE: Number Formatting

    Employee
    Posted 02-17-2015 07:08

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

    Originally posted by: andycooper

    Ernest and I have been working to improve the initial script, the graph below will show string values with numeric formats up to +/- 999,999,999.99.

    Number Format.brg

    Thanks

    Andy


  • 5.  RE: Number Formatting

    Employee
    Posted 03-10-2015 20:30

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

    Originally posted by: myrnab

    Thanks so much for your help. I will give this a go.


  • 6.  RE: Number Formatting

    Employee
    Posted 03-10-2015 20:39

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

    Originally posted by: ryeh

    Here's another way to do it. This one uses RegEx. It looks simpler, but that's because all the hard work is done within the pattern, which I Googled.
    Attachments:
    separator.brg


  • 7.  RE: Number Formatting

    Employee
    Posted 03-10-2015 20:51

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

    Originally posted by: myrnab

    Hi andycooper,
    Thanks for sharing the graph. I've run the graph and seen the output. I would not have been able to do this, ie. put the commas depending on the length of the numeric field. I can probably just concatenate the $ sign as needed. this solves my problem of formatting but because the output is now a string of characters, once i output it to Excel, i will be unable to perform numeric functions on the numbers. My report is intended to go to different people within the business and each one can perform their own analysis on the results.... eg. do their own pivots... sum certain fields including the ones that i would have formatted. Is there a way i can format a number (with $'s and commas) and still maintain its numeric characteristics. I am asking too much???


  • 8.  RE: Number Formatting

    Employee
    Posted 03-10-2015 21:20

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

    Originally posted by: myrnab

    Hi ryeh.... this is similar to what andy did but it does look at lot simpler.... less coding :D
    thanks for sharing.


  • 9.  RE: Number Formatting

    Employee
    Posted 03-11-2015 03:17

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

    Originally posted by: andycooper

    Originally posted by: myrnab
    					

    Hi andycooper,
    Thanks for sharing the graph. I've run the graph and seen the output. I would not have been able to do this, ie. put the commas depending on the length of the numeric field. I can probably just concatenate the $ sign as needed. this solves my problem of formatting but because the output is now a string of characters, once i output it to Excel, i will be unable to perform numeric functions on the numbers. My report is intended to go to different people within the business and each one can perform their own analysis on the results.... eg. do their own pivots... sum certain fields including the ones that i would have formatted. Is there a way i can format a number (with $'s and commas) and still maintain its numeric characteristics. I am asking too much???
    Hi myrnab,

    To the best of my knowledge the only was to pass the format is as a string. When saved to Excel, the values should be recognised as numbers stored as text and can be converted to number format.

    Thanks


  • 10.  RE: Number Formatting

    Employee
    Posted 06-07-2015 13:03

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

    Originally posted by: ejones

    I've started working on a node that will help with formatting numbers. It gives you some control over the characters used for the decimal and grouping (thousands) delimiter. It gives you control over the format used to display the number and defaults to the format used in the locale of the LAE server. Negative numbers can be shown in parenthesis with a format definition like this, "#,##0.00;(#,##0.00)". For details about the syntax of the format look at this page, http://docs.oracle.com/javase/7/docs...malFormat.html

    Internally, it uses the DecimalFormat Java class which has a lot of features I'd like to add to the node. I'm seeing this as a prototype of what the node might look like if it fully supported most/all of the DecimalFormat functionality.
    Attachments:
    NumberFormat.brg