Need to check number for decimal precision

Is there the ability in Eggplant to check a number for precision format?

So in my scenario I open a file in an editor, copy the data I want, paste it via the remoteClipboard into a variable. At this point I would like to verify the precision of the number. So if I have a number that has a format of 12.4f, I want to verify that the total length of the value is not longer than 12 digits and that the decimal portion is exactly 4 digits.

I have not seen any examples to do this nor can I find any ability in Eggplant to do this. I can get the total length by using the length function but I can’t seem to figure out how to check the decimal portion of the number.

Thanks!

Hi paisak,
eggplants Sensetalk supports regular expression
http://docs.eggplantsoftware.com/ePF/SenseTalk/stk-pattern-language.htm#regex
but you also can use its pattern language, what is more readable.
put <1 to 8 digits, “.”, 4 digits> matches yourVal
http://docs.eggplantsoftware.com/ePF/SenseTalk/stk-elements-pattern-matching.htm
BR

1 Like

Thanks so much Gamma! I got my 12.4f example above to work by implementing the following:

if <1 to 6 digits, “.”, 4 digits> matches myVar then
LogSuccess “Precision is correct”
else
LogError “Precision is NOT correct”

1 Like

Hi paisak,
why not using ‘assert’ to get the same in one line:
assert <1 to 6 digits, “.”, 4 digits> matches myVar with error “Precision is correct”
BR

That worked. Thanks again! That will get rid of a ton of lines too.

Having problems again with this issue when dealing with negative numbers. So I tried the following and it did not work:

assert <1 to 6 digits, “.” 4 digits> matches negative myVar with error “Precision is correct” and for my example the number I am dealing with is -0.000000 and so it complains that my pattern is not equal to 0. I just want my 1 to 6 digits to be signed. I also tried using signed in the 1 to 6 digits section and I can’t get the format right.

Edit: there probably is no number such as -0.000000 but I have to deal with it here. I even added a positive or negative in front of the 1 to 6 digits and it still complains that the pattern does not match -0.000000 even though it does. If the negative number is non-zero then the “matches negative” works fine only.

Any ideas?

Hi paisak, the match operator knows this:" maybe a …", so your issue can be handled with assert <maybe a “-”, 1 to 6 digits, “.” 4 digits>
BR