Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 43
Registered: ‎07-23-2013
My Device: Z10
My Carrier: Vodacom
Accepted Solution

Addition problem in QML - 'var' statement

Hi,

 

I have the following qml code (syntax copied from 'custom picker - cascadescookbook' sample) which returns a result into a variable 'cost' and then gets displayed in a predefined textfield{} . text property.

 

var cost = (weight * grade.costkg) + finish.extracost;

The calculation works with the multiplication part. When I insert the addition '+ finish.extracost', it still calculates the multiplication correctly but it appends the value of the addition (finish.extracost) to the end of the result, like a string, instead of doing the addition.

 

So.. giving an example of what I need... (25 * 2) + 20 answer 70

What I'm incorrectly getting instead is (25 * 2) + 20 answer 5020

 

I would like to keep this in QML if possible although I suspect the answer may lie in the C++ ?

 

Help appreciated in advance.

Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: Addition problem in QML - 'var' statement

var cost = (weight * grade.costkg) + Number(finish.extracost)

Developer
Posts: 43
Registered: ‎07-23-2013
My Device: Z10
My Carrier: Vodacom

Re: Addition problem in QML - 'var' statement

It worked! Thank you very much Yamil. It's a simple solution but I definitely learnt something here.