smarty math returns comma instead of point - decimalformat

doing this opperation in Smarty
{math equation=1.1+0.7 format="%.2f"}
I get a result with a comma separated decimal of 1,80
No idea of how to get a 1.80 value.
Thnx so much.

The only solution i have found is to replace the comma with a poin.
math|replace:",":"."
Hope it helps someone.

Related

Regexp - recognize trailing 0 for decimal numbers?

I need a regular expression which can find a trail of "0" in the decimal space.
F.e. following format should be recognized:
1.0
1.00
1.000
etc...
Is there somekind of "wildcard" for that?
Any idea?
Thanks,
KS
Please see the following regular expression that matches trailing zeros on the end of any decimal. Note that this does match trailing zeros in the case where there is a meaningful decimal value, but zeros occur after.
https://regex101.com/r/BJvLrO/1/
When working with regex, it is very valuable to always use a tool like https://regex101.com or https://regexr.com. Both of these tools will help you truly understand the Regular Expression. Try hovering your mouse over the different elements of the regex in my example and the tool will describe each part. You can also read the "Explanation" section to on the right side.

Replacing characters in strings. Intersystems cache SQL

I recently reached out to this community for assistance on how to remove a specific character from the very beginning of a string and at the end of a string. In my case, the character I needed removed was an ampersand. Here is the code I used that resolved my issue:
select substr((rpu.userrole), 2, length(rpu.userrole) - 2) AS UserRole
However, now I am left with strings like this after the very first and last ampersand have been removed:
BachelorLvlProvider&ShortTermAccess&WrkflwBachelorLvl
As you can see, there are anywhere between zero and several ampersands separating these role positions. Cache seems to have a lot of functions to concatenate strings, but am not having any luck finding functions to replace characters in a string. There is a "$replace" function but I believe it only works in ObjectScript.
Can anyone assist me in replacing all ampersands regardless of how many there are in each string with the literal ', ' ? I need to separate these with a single comma and one space. I included the tick marks as that are what I use in the code for my strings.
Any assistance would be greatly appreciated.
Thanks!
You can use REPLACE in SQL as well (Caché/Ensemble and IRIS).
SELECT REPLACE('BachelorLvlProvider&ShortTermAccess&WrkflwBachelorLvl','&',',') as UserRole
will give
BachelorLvlProvider,ShortTermAccess,WrkflwBachelorLvl
My test below works perfectly well :
SELECT REPLACE(substr(('&BachelorLvlProvider&ShortTermAccess&WrkflwBachelorLvl&'), 2, length('&BachelorLvlProvider&ShortTermAccess&WrkflwBachelorLvl&') - 2),'&',',') as UserRole

Split a string to only use the middle part in SQL

I have a string
ABC - ABCDEFGHIJK - 05/07/2016
I want to only use the ABCDEFGHIJK section and remove the first and third parts of the string.
I have tried using SUBSTRING with CHARINDEX, but was only able to remove the first part of the string.
Anyone help with this?
You can use SUBSTRING_INDEX() and TRIM() for spaces :
SELECT TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(string_col,'-',2),'-',-1)) AS Strig_Col
FROM YourTable;

REPLACE 2 string with replacement string in sql

SSN=LTRIM(RTRIM(REPLACE(A.SSN,'-','')))
Can some one please help me? This code replaces "-" with '' of ssn column which works. But now I want to also replace dots . with '' string. Can someone help me how to replace both - and .?
Any help will be highly appreciated.
Thank you
Use one more replace
LTRIM(RTRIM(REPLACE(REPLACE(A.SSN,'-',''),'.','')))
If you are using Oracle, the easiest way to do this is using regexp_replace to only get the digits.
regexp_replace(ssn, '\D', '')

Avoiding Lookbehind in Postgres

In a Postgres query I wrote, I'm trying to find an empty char between a digit and a char.
The Raw-Data looks pretty similar to this:
"X 1111-11-112222-22-22YY 3333-33-334444-44-44ZZZ5555-55-556666-66-66AAA7777-77-778888-88-88B 9999-99-991111-11-11"
I would like to split this into following table:
X 1111-11-112222-22-22
YY 3333-33-334444-44-44
ZZZ5555-55-556666-66-66
AAA7777-77-778888-88-88
B 9999-99-991111-11-11
So, normally i would do this by defining the Regex (?<\d)(?=[A-z]) which is giving me the empty char between the chars and digits, but Postgres doesn't support lookbehinds.
Anyone an idea how to fix this?
Thanks in advance!
(\w+\s*[\d-]+)
This will give all the groups.See demo.
http://regex101.com/r/nW8dX7/1
I would do a replace with a character you can then later split on. I'm not familiar with psql but something like:
split('~', replace(value, '\d(?=[A-z])', '$0~'))