I'm trying to display a numeric value of 0.733675715 using liquid templates.
Following code
{%- assign rate = 0.733675715 -%}
{{ rate }}
Results in: 0.7336757
I could not find a way to:
convert numeric value to string
force liquid to display all decimal places
--edit
Note: DotLiquid is used by Azure logic apps integration accounts to do transformations between JSON/XML/Text
I found the issue in dotLiquid library.
The fix can be found in this PR: https://github.com/dotliquid/dotliquid/pull/353.
Basically, in the assign statement, dotliquid is parsing the value as float[1], hence the lost precision.
// Floats.
match = FloatRegex.Match(key);
if (match.Success)
{
// For cultures with "," as the decimal separator, allow
// both "," and "." to be used as the separator.
// First try to parse using current culture.
if (float.TryParse(match.Groups[1].Value, NumberStyles.Number, FormatProvider, out float result))
return result;
// If that fails, try to parse using invariant culture.
return float.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture);
}
https://github.com/dotliquid/dotliquid/blob/b415f6aaa5b66fdbfa9c5d676427c7663c1e98e3/src/DotLiquid/Context.cs#L347
Related
I have an xml
<family>
<child_one>ROY</child_one>
<child_two>VIC</child_two>
</family>
I want to fetch the value from the XML based on the dynamic tag in ESQL. I have tried like this
SET dynamicTag = 'child_'||num;
SET value = InputRoot.XMLNSC.parent.(XML.Element)dynamicTag;
Here num is the value received from the input it can be one or two. The result should be value = ROY if num is one and value is VIC if num is two.
The chapter ESQL field reference overview describes this use case:
Because the names of the fields appear in the ESQL program, they must be known when the program is written. This limitation can be avoided by using the alternative syntax that uses braces ( { ... } ).
So can change your code like this:
SET value = InputRoot.XMLNSC.parent.(XMLNSC.Element){dynamicTag};
Notice the change of the element type as well, see comment of #kimbert.
I like to access a specific JSON object value, where the access path contains a dynamic value. The dynamic value is calculated beforehand during the dialog process.
How can I do this in a "set property" node? I did not find a good working approach.
Here my approach, which leads to no useful result.
=user.api_content.prediction.intents.${virtualagent.intent}.score
Thanks
Which language are you using? You should be able to just address it directly without a string designator. For example, here is how I get the score for the top intent, where intent is a variable property. You would just want to get it via the [] notation instead of the . notation.
var intent = LuisRecognizer.topIntent(recognizerResult);
if (recognizerResult.intents[intent].score < 0.5) {
intent = 'None';
}
In my tablesorter I applied this addParser to the column I'm showing here in this question. And it works well, but I found an unexpected behaviour when I filter in a way.
The results without filtering will be like this next picture:
The code for the addParser is the next one:
$.tablesorter.addParser({
// set a unique id
id: 'kilogramos',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
return parseFloat(s.replace(' Kg','').replace('.',''));
},
// set type, either numeric or text
type: 'numeric'
});
If I use the ">=" it seems to apply the addParser, because I can get rid the "." and the " Kg" of and it finds the 11.689 Kg results.
But seems that if I don't use the operators like ">", or ">=", etc. the behaviour change and it needs the dot to find what you are trying to get. In the next pictures I show what I mean.
In this last picture, I don't use the operators and I doesn't find any results. Instead, it needs now the "." and also even the " Kg" it works. The next image proves that:
I just don't want to need this "." or " Kg" to be used in any case.
Any help? Thanks
I think all you're missing is a "filter-parsed" class in the header (demo)
<th class="sorter-kilogramos filter-parsed">Kg</th>
In the Expression Builder for the Workplace Process Designer, I have an attachment variable of type String[] (array of strings). I'd like to add some elements to it using the Expression Builder, but I can't work out the syntax. Has anyone done this? Is it even possible to add elements to an existing array in Expression Builder?
The arraytostring solution only works if there is only one element the array.
Assign the additional value with the following expression:
stringarray[elementcount(stringarray) + 1] = value
The expected 'array out of bound exception' and the resizing of the array is handled during the assignment.
I originally thought that it is not possible that we had to resort to have a custom java component to do the job, however I had run a small experiment that should serve as a workaround for your case.
Suppose you have String[] arrayType={"string1, string2"}, you can use the following expression as a value for your updated array:
{(arraytostring(arrayType, " ", " ,", ","))+"string3"}
What I did was that,
First, I used arraytostring function to convert the array to a string separated by comma with a comma left at the end. My output is similar to string1,string2,
Second, I appended the string that I want to add to the end of the string, so that my output is string1,string2,string3
Lastly, I assigned the value above to my array, using the array expression format {}, so my final evaluated string is {string1,string2,string3}
For more information about array functions, please follow the link below:
https://www.ibm.com/support/knowledgecenter/SSNW2F_5.2.1/com.ibm.p8.pe.user.doc/bpfe003.htm
I had a case like this, here is what I did:
I get the array from the attachment using the CE-Operation and store
in an array property on the workflow
Then I used the following to
{(arraytostring(workflowArray, " ", " ,", ","))+workflowStringProp}
using the CE-Operation again to set the array in the attachment with
the workflowArray.
Given this ApiController:
public string TestString() {
return "The value is: " + 1.23;
}
public double TestDouble() {
return 1.23;
}
With the browser's language set to "fr-FR", the following happens:
/apiController/TestString yields
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">The value is: 1,23</string>
/apiController/TestDouble yields
<double xmlns="http://schemas.microsoft.com/2003/10/Serialization/">1.23</double>
I would expect TestDouble() to yield 1,23 in the XML. Can anyone explain why this isn't the case and, more importantly, how to make it so that it does?
It is because the conversion from double to string happens at different stage for each API. For the TestString API, double.ToString() is used to convert the number to a string using CurrentCulture of the current thread and it happens when the TestString method is called. Meanwhile, the double number which is returned by TestDouble is serialized to string during the serialization step which uses GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Culture.
In my opinion, both should use InvariantCulture. On the consumer side, the values will be parsed and be formatted with the correct culture.
Update: this is only used for JsonFormatter. XmlFormatter doesn't have such a setting.
Update 2:
It seems (decimal) numbers need special converter to make it culture-aware:
Handling decimal values in Newtonsoft.Json
Btw, if you want o change data format per action/request, you can try the last piece of code of the following link: http://tostring.it/2012/07/18/customize-json-result-in-web-api/