I have a case where I am getting an array of dictionary, and some of the items in the array are decimals that are in scientific notation. For example, I get 3.396929e+14 instead of 339692900000000. What would be the most efficient way to convert all numbers with scientific notation in any list of dictionaries into text so that they are readable in Appian?
It needs to work with any dictionary, so I cannot rely on consistent key value pairs.
Here is a real example of the data I am receiving. I have bolded some examples:
Discussion posts and replies are publicly visible
For this to work with any dictionary, you will be doing some json conversions. Here is a quick sample to get you going, re-using some code from Stefan in another thread on dictionary manipulation:
a!localVariables( local!data: { {field1: "value1asdf"}, {field2: "1.234e+10"}, {field3: "value3test"} }, reduce( updatecdt(_,_), cast('type!{http://www.appian.com/ae/types/2009}Dictionary', {}), a!forEach( items: local!data, expression: { a!localVariables( local!pair: split(a!toJson(fv!item),":"), local!key: stripwith(local!pair[1],"""{"), local!value: stripwith(local!pair[2],"""}"), a!fromJson( substitute( a!toJson( { p_l_a_c_e_h_o_l_d_e_r: if( search("e+",local!value)>0, rule!chris_test_convert_scientific_notation(value: local!value), local!value ) } ), "p_l_a_c_e_h_o_l_d_e_r", local!key ) ) ) } ) ) )
Helper rule!chris_test_convert_scientific_nocation(value [text]):
a!localVariables( local!split: split(ri!value,"e+"), local!count: len(split(local!split[1],".")[2]), concat( stripwith(local!split[1],"."), makerange(tointeger(local!split[2])-local!count,"0") ) )
Are you getting the decimals in e-notation or is it just the way Appian displays it? In the latter case, this has been discussed here multiple times. If you need to display long decimals to your user, then use the text() function to format it in the way you like.
I am receiving the values in e notation. I never need to show them to my user, but I need to pass the values back through an integration as text. I know about the text fuction, the issue is more doing it dynamically with a list of dictionary that will never have the same key value pairs
The get the plugin dictionary manipulation (https://community.appian.com/b/appmarket/posts/cdt-manipulation), use the function getKeysFromDictionary() and a foreach to iterate on the keys. In that plugin is a function createDictionary() which should help you creating the output.
Thank you both Stefan Helzle and Chris.I have included what I came up with below. It is formatted to paste into a blank interface in order to monitor performance. It is working, but is there any way to make it more efficient? I noticed that for a medium size data set of 375 rows similar to the data in this example, local!dataFinal took almost 1 second.
Stefan Helzlethanks for this, it looks good and performs about the same as my original version. Now I am running into a different issue, and I am wondering if you have any ideas, or know why it is happening. There are a few places where I need to sort the resulting list of dictionary by different fields in the dictionary. Unfortunately, after I apply either your or my versions of the code to switch the format of the numbers, I get an error. I have included two scenarios to showcase this:Scenario 1: Original data, no errorThe thing that is confusing me, is that the Type for both the the original data, and the data after running the number formatting code (either your version or mine), is list of dictionary. Do you know why it is breaking in one scenario, and not the other? I feel like I am missing something obvious haha.
I just moved to another company and have a new account so I cannot modify older posts anymore. Please contact Appian support at support@appian.com.