Looking for your expert help where I am getting a number as 2 but would like to have that displayed as 2.0 where as if its 2.5 then this is fine, I would like to display 2.5 only.
I am using xquery version "1.0";
I am trying to use format-number function but seems like this not supported with version 1.0
<ns0:value>{data($InputNumber/ns0:count)}</ns0:value>
where if count is 2
then it should display as
<ns0:value>2.0</ns0:value>
and if count is a decimal value as 2.5 then it should be the way it is
kindly advise
You should be able to check whether the input string contains a dot and otherwise append .0 at the end :
let $in:=data($InputNumber/ns0:count)
return if (contains($in, '.')) then $in else concat($in, '.0')
Related
I am currently trying to figure out how to always get a leading 0 when getting current date time.
The following is the way I am currently doing it:
${date} = Get Current Date result_format=datetime
${dateyear}= Convert To String ${date.year}
${datemonth}= Convert To String ${date.month}
${dateday}= Convert To String ${date.day}
${datehour}= Convert to string ${date.hour}
${dateminute}= Convert to string ${date.minute}
The problem is that when I get date.day/minute/hour/, I get back 1-9 instead of 01-09. I am using the values to enrich a json, which expects 2 characters for each, so passing 1 results in an error, while passing 01 will work fine.
You can use zfill() function to pad strings:
${dateminute}= Set Variable 5
${dateminute}= Evaluate '${dateminute}'.zfill(2)
In my ML db, we have documents with distributor code like 'DIST:5012' (DIST:XXXX) XXXX is a four-digit number.
currently, in my TDE, the below code works well.
However instead of concat all the raw distributor codes, I want to simply concat the number part only. I used the fn:substring-after XQuery function. However, it won't work. It won't show that distributorCode column in the SQL View anymore. (Below code does not work.)
What is wrong? How to fix that?
Both fn:substring-after and fn:string-join is in TDE Dialect page.
https://docs.marklogic.com/9.0/guide/app-dev/TDE#id_99178
substring-after() expects a single string as input, not a sequence of strings.
To demonstrate, this will not work:
let $dist := ("DIST:5012", "DIST:5013")
return substring-after($dist, "DIST:")
This will:
for $dist in ("DIST:5012", "DIST:5013")
return substring-after($dist, "DIST:")
I need to double check what XPath expressions will work in a DTE, you might be able to change it to apply the substring-after() function in the last step:
fn:string-join( distributors/distributor/urn/substring-after(., 'DIST:'), ';')
I am trying to format a date string using the Apache Nifi expression language and the Replace Text processor(regex). Given a date string
date_str : "2018-12-05T11:44:39.717+01:00",
I wish to convert this to:
correct_mod_date_str: "2018-12-05 10:44:39.717",
(notice how the date is converted to UTC, and character 'T' replaced by a space.)
To do this, I am currently using:
toDate("yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX"):format("yyyy-MM-dd HH:mm:ss.SSS", '+00:00')
and this works perfectly.
However, when the date string has 6 digits in ms, rather than 3, things break:
another_date_str: "2018-12-05T11:44:39.717456+01:00"
is converted to:
incorrect_mod_date_str: "2018-12-05 10:56:36.456"
It seems the first 3 digits in the ms precision interferes with the conversion.
Appreciate inputs to resolve this - what am I missing?
Regards
seems that's a limitation in java.
according to java documentation there is no support of more then 3 milliseconds digits.
https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
the simplest way is to remove extra digits like this:
attr:replaceAll('(\.\d{3})\d*','$1'):toDate("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"):format("yyyy-MM-dd HH:mm:ss.SSS", '+00:00')
I ran into a similar issue with date time encoded in ISO 8601. The problem is, that the digits after the second are defined as fragment of a second, not milliseconds.
See answer to related topic
I need your help!
Im kinda new whats regarding python and "hex".
I have a site where people can enter their own HEX-Color for their messages.
So currently i have everything built in except the "isHEXColor" Check..
I realy dont know how i can be sure that the user gave a valid HEX-Color-Code.
Currently im just checking if the len is 6 digits, nothing more.
if not len(color) == 6: return error("HEX-Color" must contain 6 characters")
Can you might help me?
And it should work for Python 2.5!
You could use a regular expression:
^#(?:[0-9a-fA-F]{3}){1,2}$
For using regular expression in python https://docs.python.org/2/library/re.html
import re
str = '#ffffff' # Your Hex
match = re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', str)
if match:
print 'Hex is valid'
else:
print 'Hex is not valid'
teoreda's proposition to use regex seems fine to me, but I think the right regex is rather:
^#(?:[0-9a-fA-F]{1,2}){3}$
(each color (r, g and b) has 1 or 2 digits and there are 3 colors)
I am trying to subtracts one count value from another but,I am facing problem in following code :
count=$?
count1=$?
(then some operations and above count values got some value suppose 1,2 respectively)
$count=$count1 - $count ==> Here it should get : 2-1=1 )
I don't know exact syntax for this so, can any one help me please?
You can use the shell's expression syntax:
count=$(($count1-$count))
the $ prefix on variables is optional inside $(()), so this can also be written as:
count=$((count1-count))
Unix provides you the command expr that lets you evaluate any arithmetic expression you want. At shell prompt try :
expr 2 - 3 + 5 '*' 8
Remember that * is used as wildcard so you need to un-specialized it in any way you want.
Then now, you could use ` to evaluate an expression at any place :
count=`expr $count1 - $count`
Be aware that all arguments MUST be separated with spaces.
This will work for Bourne-shell which is the one recommended for shell-scripts.