How can I format a Twig Calculation?
Currently I am using the following Code:
£{{ (Results.Result._symbol_at_attributes.adults +
Results.Result._symbol_at_attributes.children) *
Results.Result._symbol_at_attributes.price / 100 * 95 }}
Current Example Output: £459.4
Needed Output: £459
You can use the builtin filter number_format.
£{{ ((Results.Result._symbol_at_attributes.adults + Results.Result._symbol_at_attributes.children) * Results.Result._symbol_at_attributes.price / 100 * 95) | number_format }}
Do note: you have to add parantheses around the calculation, otherwise the filter would only be applied to the last part of the calculation due to the precedence of operators
Related
I use thymeleaf with template for TEXT to output some handcrafted text-files. Output should be
* smallText[description]
And I write in the thymeleaf template
* [(#{value}][[(#{value2}]]
But its not working and outputs (the "[" is missing)
* smallTextdescription
I also tried
* [(#{value}][ [(#{value2}] ]
But I do not want spaces behind the "[" Any ideas?
Have you tried using the following syntax th:text?
/*[# th:text="|*${value}[${value2}]|"]*/
In this case the output is:
*smallText[description]
When you are using TemplateMode.TEXT, you can use the following syntax:
[#element ... /]
This is the text-mode equivalent of the more familiar HTML-based syntax, such as:
<div th:text=""...></div>
So, you can now write something like this in your text file (the Thymeleaf template):
[# th:text="'* ' + ${value} + '[' + ${value2} + ']'" /]
This produces:
* smallText[description]
NOTE - in my case I don't have any #{...} message values to test with, so I'm just using ${...} variables in my test. But the same syntax applies to #{...} values.
See textual template modes for more details.
The only way I found was to replace [ with [([)] and ] with [(])].
* [(#{value})][([)][(#{value2})][(])]
Hoping for smarter and more elegant solutions out there.
I need to get the value that is between !03 and !03.
Example:
JDC!0320151104!03OUT
I should get following string in return: 20151104
NOTE: The string isn't always 22 characters long, but I am only concerned with the value that is between !03 and !03.
This is what I have so far. I couldn't make any progress further than this:
SELECT
SUBSTRING(
RegStatsID,
CHARINDEX('!', RegStatsID) + 3,
CHARINDEX('!', REVERSE(RegStatsID))
)
From TableX
Great that you found a solution!
This might be better:
By replacing the "!03" with XML-tags you can easily pick the second "node". Your string will be transformed into <x>JDC</x><x>20151104</x><x>OUT</x>:
DECLARE #test VARCHAR(100)='JDC!0320151104!03OUT';
SELECT CAST('<x>' + REPLACE(#test,'!03','</x><x>') + '</x>' AS XML).value('/x[2]','datetime')
One advantage was to get the value between the two "!03" typed. In this case you get a "real" datetime back without any further casts. If the value there is not a datetime (or date) in all cases, you just use nvarchar(max) as type.
Another advantage was: If you - why ever - need the other values later, you just have them with .value('/x[1 or 3]'...)
I was able to get it right by doing following:
SELECT
SUBSTRING(
RegStatsID,
CHARINDEX('!', RegStatsID) + 3,
len(RegStatsID) - CHARINDEX('!', RegStatsID ) - 2 - CHARINDEX('!', Reverse(RegStatsID))
)
I found that excel has an if feature that is
= IF(booleanExpression, trueValue, falseValue)
I am trying to use it but i think there is something wrong with my boolean statement.
I have:
=IF ( ( ((.8*P20)>(1.35*H20)) AND ( (.8*P20)<(2*H20))), (.8*P20), (1.35*H20))
I'm assuming my problem is with the AND part. Is there a way i can check two conditions here?
The syntax of the AND is different:
=IF(AND(statement1, statement2), v_if_true, v_if_false)
VBA uses AND differently:
If statement1 AND statement2 Then
Just use AND to equate multiple values:
=IF(AND(0.8 * P20 > 1.35 * H20, 0.8 * P20 < 2 * H20), 0.8 * P20, 1.35 * H20)
Btw your use of brackets was a bit excessive so I've removed them here.
See this Microsoft article for more information on AND: https://support.office.com/en-my/article/AND-function-5f19b2e8-e1df-4408-897a-ce285a19e9d9
I have a string field with mostly numeric values like 13.4, but some have 13.4%. I am trying to use the following expression to remove the % symbols and retain just the numeric values to convert the field to integer.
Here is what I have so far in the expression definition of Cognos 8 Report Studio:
IF(POSITION('%' IN [FIELD1]) = NULL) THEN
/*** this captures rows with valid data **/
([FIELD1])
ELSE
/** trying to remove the % sign from rows with data like this 13.4% **/
(SUBSTRING([FIELD1]), 1, POSITION('%' IN [FIELD1])))
Any hints/help is much appreciated.
An easy way to do this is to use the trim() function. The following will remove any trailing % characters:
TRIM(trailing '%',[FIELD1])
The approach you are using is feasable. However, the syntax you are using is not compatible with the version of the ReportStudio that I'm familiar with. Below you will find an updated expression which works for me.
IF ( POSITION( '%'; [FIELD1]) = 0) THEN
( [FIELD1] )
ELSE
( SUBSTRING( [FIELD1]; 1; POSITION( '%'; [FIELD1]) - 1 ) )
Since character positions in strings are 1-based in Cognos it's important to substract 1 from the position returned by POSITION(). Otherwise you would only cut off characters after the percent sign.
Another note: what you are doing here is data cleansing. It's usually more advantageous to push these chores down to a lower level of the data retrieval chain, e.g. the Data Warehouse or at least the Framework Manager model, so that at the reporting level you can use this field as numeric field directly.
I have Excel sheets where the same column can contain a value with % formatting and also with decimal notation.
To clarify: In Excel both have the same formatting but due to different Excel versions (locations) SSIS shows them like this:
1,3% or 0.814260540128523
These values come in as strings so I'm trying to figure out a way to divide the % formatted values by 100 and leave the others as is.
Initially I used:
(DT_R8)[F5_CONV] < 1 ? (DT_R8)[F5_CONV] : (DT_R8)[F5_CONV] / 100
in a second derived column but I then realized that 0,23% is also a possible value.
I think something like this should do it but I'm having trouble with the DT_WSTR and DT_R8 types.
(F5 == "" || ISNULL(F5)) ? NULL(DT_WSTR,40) : FINDSTRING(F5,"%",1) > 0
? (DT_WSTR,40)REPLACE(REPLACE(F5,".",","),"%","") / 100
: (DT_WSTR,40)REPLACE(F5,".",",")
Hope you can help me out here.
Thank you.
(F5 == "" || ISNULL(F5)) ? NULL(DT_WSTR,40) : FINDSTRING(F5,"%",1) > 0
? (DT_WSTR,40)((DT_R8)REPLACE(REPLACE(F5,".",","),"%","") / 100)
: (DT_WSTR,40)REPLACE(F5,".",",")
You can also use script component. Here is a quick solution; you may need to add validations for null. Let us know, if you need help.