I am having completing some basic match operations using the Velocity Templating Language in Polarion ALM.

I was able to do the following with success:

$math.toInteger($requirement.get(3))

$requirement.get(3) is a Long number value. Doing that converts it to the integer value.

So seeing that I have $math available to me, following the documentation for VTL: https://velocity.apache.org/tools/1.2/g ... #toDouble()

I am attempting to use toDouble(). by trying this:

#set($value = $math.toDouble(1.3))

I would have expected $value is a double and equal to 1.3 But that doesn't work. Any ideas on what else to try?

## How to do math with decimals in Polarion

### Re: How to do math with decimals in Polarion

Having the Wiki Scripting Tools extension installed (see http://extensions.polarion.com/extensio ... ting-tools) you can use the $mathTool to perform several calculations, e. g.:

In current versions of Polarion $mathTool seems to be build in - no separate extension installation required.

More information about the $mathTool object can be found in https://velocity.apache.org/tools/2.0/a ... hTool.html

Code: Select all

`#set($f_complexity = $mathTool.toDouble($wi.getCustomField("complexity")))`

In current versions of Polarion $mathTool seems to be build in - no separate extension installation required.

More information about the $mathTool object can be found in https://velocity.apache.org/tools/2.0/a ... hTool.html

### Re: How to do math with decimals in Polarion

adbarads wrote:#set($value = $math.toDouble(1.3))

I would have expected $value is a double and equal to 1.3 But that doesn't work. Any ideas on what else to try?

If you would like to assign the decimal value 1.3 (which does not come from a work item field) to a variable, then you need to place "1.3" in quotation marks, because the most recent method documentation of the mathTool says, that toDouble can only take an integer or String as parameter

It would work like this:

Code: Select all

`## assigning a double`

#set($value = $mathTool.toDouble("1.3"))

## printing the value:

$value

Of course, it would also work like this: 13 divided through 10. 13 because it is 1.3 multiplied by the power of ten that is equal to the amount of your decimal places. If you want to assign 1.3456 with this procedure, you need to divide 13456 through 1000.

Code: Select all

`## assigning a double the cumbersome way`

#set($valueDouble = $mathTool.div(13,10))

## printing the value:

$valueDouble

See the link to latest documentation here:

https://velocity.apache.org/tools/2.0/a ... hTool.html

Return to “Polarion Application Lifecycle Management (ALM)”

### Who is online

Users browsing this forum: BrianPrick and 7 guests