How do I compare non integer numbers using freemarker templete - numbers

I use freemarker template in my Java application to load my pages in my Java Spring MVC Web Application. Usually, I use built-ins like gt, lt, lte, gte etc to compare two numbers.
Currently I have a situation where there value returned from the controller is a double. Now I have values such as -1.0 or 0.0. All I am trying to do is check if the value is less than 0 or equal to 0 so that I can conditionally display my contents as I always do.
Is there any way to compare numbers in freemarker when the number is double. I could not find any suitable solutions online.

As far as I know, Freemarker doesn't really treat doubles differently than integers. This is from Apache Freemarker Docs:
Number: For example the price of a product. Whole numbers and non-whole numbers are not distinguished; there is only a single number type. So for example 3/2 will be always 1.5, and never 1. Just like if you are using a calculator.
I have used this and other similar instances in my templates with no issues where salesTaxRate is a double in java:
<#if (orderSummary.order.ioItems[0].salesTaxRate > 0)>
<td>Tax (${orderSummary.order.ioItems[0].salesTaxRate}%):</td>
<#else>
<td>Tax:</td>
</#if>
What is happening when you try the comparison? Are you running into issues where the value is supposed to be zero but is actually some insignificant value (0.000000000001)?

Related

Reading CSV file with Spring batch and map to Domain objects based on the the first field and then insert them in DB accordingly [duplicate]

How can we implement pattern matching in Spring Batch, I am using org.springframework.batch.item.file.mapping.PatternMatchingCompositeLineMapper
I got to know that I can only use ? or * here to create my pattern.
My requirement is like below:
I have a fixed length record file and in each record I have two fields at 35th and 36th position which gives record type
for example below "05" is record type which is at 35th and 36th position and total length of record is 400.
0000001131444444444444445589868444050MarketsABNAKKAAAAKKKA05568551456...........
I tried to write regular expression but it does not work, i got to know only two special character can be used which are * and ? .
In that case I can only write like this
??????????????????????????????????05?????????????..................
but it does not seem to be good solution.
Please suggest how can I write this solution, Thanks a lot for help in advance
The PatternMatchingCompositeLineMapper uses an instance of org.springframework.batch.support.PatternMatcher to do the matching. It's important to note that PatternMatcher does not use true regular expressions. It uses something closer to ant patterns (the code is actually lifted from AntPathMatcher in Spring Core).
That being said, you have three options:
Use a pattern like you are referring to (since there is no short hand way to specify the number of ? that should be checked like there is in regular expressions).
Create your own composite LineMapper implementation that uses regular expressions to do the mapping.
For the record, if you choose option 2, contributing it back would be appreciated!

IBM Watson Assistant: Regular expressions with context variables

I am gathering some context variables with slots, and they work just fine.
So I decided to do in another node of the conversation, check if one of these context variables is a specific number:
I was thinking on enabling multi-responses and check if, for example $dni:1 (it is an integer, pattern of 1 integer only), or if it is 2 or 3:
But this is not working. I was trying to solve it for some days with different approaches but I really cannot find a way through it.
My guess is that a context variable has a value, and you can print it to use it like responding with the user's name and stuff like that (which indeed is useful!), but comparing values is not possible.
Any insights on this I can receive?
Watson Assistant uses a short-hand syntax but also supports the more complex expressions. What you could do is to edit the condition in the JSON editor. There, for the condition, use a function like matches() on the value of the context variable.
Note that it is not recommended to check for context variables in the slot conditions. You can use multi-responses. An alternative way is to put the check into the response itself. There, you can use predicates to generate the answer.
<? context.dni==1 ? 'Very well' : 'Your number is not 1' ?>
You can nest the evaluation to have three different answers. Another way is to build an array of responses and use dni as key.
Instead of matching to specific integers, you could consider using the Numbers system entity. Watson Assistant supports several languages. As a benefit, users could answer "the first one", "the 2nd option", etc., and the bot still would understand and your logic could still route to the correct answer.

How to get rid of zeros in the section numbering in LATEX report document class?

So I'm writing a report using Latex and the document class I am using is report:
\documentclass[a4paper]{report}
But for some reason the section numbering is written so that it is preceded with "0.", for example it looks like:
0.1 Introduction
0.2 Theory
0.3 Experimental Method
and so on.
Can somebody help me get rid of those zeros so that it appears how it is supposed to be?
report assumes you'll be using \chapters as your main sectional unit. As such, all sectional units are marked "relative" to the \chapter counter. Specifically, \section counters are set using \thechapter.\arabic{section}. Either use
\documentclass[a4paper]{article}
to remove any reference of \chapters, or add
\renewcommand{\thesection}{\arabic{section}}
to your document preamble.
The former would have greater impact on the actual output, as the setting of a \title and possibly the layout may be different. The latter would just remove the \chapter counter from being printed with every \section (and lower-level section unit).

How to store the values of the links in an array using selenium IDE

I used storeXPathCount to get the set of links matching a specific format.
Lets consider the count would be 12.
So there are 12 different links available which will have different dates like 20, 21, 22,.....31.
I want to store these values of the links in an array and use the values one by one.
Getting the first value from array(i.e. 20).
Check for condition.
If condition fails, increment the array count by 1.(It should be 21).
Again check for condition and increment the array.
You can execute any javascript with store eval, you can also create a Selenium ide plugin in javascript.
See also this answer selenium ide loop through array variables which seems to be related to this question.
Also there's a sideflow plugin for selenium ide which might make things simpler.
Selenium IDE - sideflow.js loops
https://github.com/darrenderidder/sideflow
This is also an example of how simple it can be to write a Selenium IDE plugin

Zend framework currency validation

How can I validate (a form element in this case) to ensure that the value is a currency?
Have looked at Zend_Validate_Float.
Needs to check that value is between 0 and 2dp.
Ideally locale-aware (as ZVF is) to allow for locale specific formatting (thousands, decimal as comma/dot)
Would also want to extend to allow/disallow negative values
And provide optional upper/lower limits.
Is the key, as I can do 3. and 4. with a chain.
Do I need regex?
AFAIK there is no validator for currency in ZF yet.
You need to write a custom one. See docs for writing custom validators.
Basically, the simplest thing you can do is to normalize input to floating point number (+ currency symbol if you need locale). But correcting user input is not a good solution.
For locale specific formatting you will probably need locale data stored in Zend_Locale_Data. But for comparing input values you will have to write custom currency converter.
Detecting used locale is not so simple, so I'd suggest creating additional select field, for choosing pre-defined format (e.g. locale) and using this value for your custom validator attached to the currency field.