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
babakar
Posts: 724
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later
Accepted Solution

how to check if number is negative in qml

  color: (ListItemData.moneyWonOrLost) ? Color.Black : Color.Red

 

money won or lost is in this format 422,846,909.58

Please use plain text.
Developer
BBSJdev
Posts: 6,094
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: how to check if number is negative in qml

[ Edited ]

Will you have negative money then?

 

Use parseFloat() to change the value to a number then do the normal less than zero check.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
babakar
Posts: 724
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: how to check if number is negative in qml

dont think it will work, because of the comma.

Workaround i did, if number arrives with string starting with -...its negative else its not.
Please use plain text.
Developer
pyth
Posts: 506
Registered: ‎01-19-2011
My Device: My Trusty Red Plane
My Carrier: Outer Space

Re: how to check if number is negative in qml

[ Edited ]

please, I repeat, PLEAAAASE use what BBSJdev wrote

feel free to report this as inappropriate, but I had to write this :smileyhappy:

-----------------------------------------------------------------------
I'm a bird from outer space. But I'm not flappy o.o
Please use plain text.
Developer
babakar
Posts: 724
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: how to check if number is negative in qml

numberss arrive to me with a comma.

like 4,345.39

it doesnt arrive 4345.39
Please use plain text.
Developer
BBSJdev
Posts: 6,094
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: how to check if number is negative in qml

[ Edited ]

@pyth Made me laugh. :smileyvery-happy:

 

@babakar if your number really does have commas in then you can use a string replace to remove the commas first.

 

If -0.00 doesn't break the logic of your code and you are not using the number for anything else then your suggestion is fine.

 

You might like to do a contains rather than a first character compare unless you are absolutely sure there will be no leading spaces or characters.

 

In the end it's safer to turn it in to a number and do a check on whether it is a number first to catch any errant data.

 

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
BlackBerry Development Advisor (Retired)
robbieDubya
Posts: 418
Registered: ‎07-18-2012
My Device: Q10
My Carrier: Bell Canada

Re: how to check if number is negative in qml

Snippet to do what BBSJdev suggests:

 

color: (parseFloat(ListItemData.moneyWonOrLost.trim().replace(/,/g,""))>=0) ? Color.Black : Color.Red

 

--
Rob is no longer associated with BlackBerry.
Please use plain text.
BlackBerry Development Advisor (Retired)
robbieDubya
Posts: 418
Registered: ‎07-18-2012
My Device: Q10
My Carrier: Bell Canada

Re: how to check if number is negative in qml

PS: You can expand that expression to highlight items that were not a number. NaN always returns false for < > comparissons...

--
Rob is no longer associated with BlackBerry.
Please use plain text.