How to do math with decimals in Polarion

Description
adbarads
Posts: 5
Joined: Mon Nov 13, 2017 7:47 pm

How to do math with decimals in Polarion

Postby adbarads » Tue Dec 19, 2017 4:48 pm

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?

martins
Posts: 181
Joined: Thu Nov 05, 2009 3:24 pm

Re: How to do math with decimals in Polarion

Postby martins » Tue Jan 02, 2018 11:11 am

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.:

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

ALMighty
Posts: 80
Joined: Wed Apr 27, 2016 10:34 am
Location: Austria

Re: How to do math with decimals in Polarion

Postby ALMighty » Tue Jan 02, 2018 2:45 pm

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
---------------------------------------------------------------------------------------------------
Playing a good game is never lame. :D
Image


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 9 guests