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
New Developer
Posts: 41
Registered: ‎02-11-2010
My Device: Bold 9000
My Carrier: AT&T
Accepted Solution

math function round() makes label invisible...

I have a grading app that figures out a percentage for an assignment and displays a letter grade.

 

with gold update, the label no longer appears when I launch the app.

Label {
                id: findGrade
                // custom property to calculate final grade percentage
                text: "Percent: " + round(grdCalc.text * 100) / 100 + "%"
                textStyle.fontWeight: FontWeight.Bold
                enabled: true
                visible: true
               
            }

 I've also tried Math.round but it doesnt seem to work. do i have to import a bb library for this to work?

 

if so, how do I know what libraries I can include in a project. is it all just

 

import bb.math 1.0??

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: math function round() makes label invisible...

It should be Math.round(). I haven't tried your code and can't right now, but try putting parentheses around all the math... "Percent: " + (Math.round(grdCalc.text * 100) / 100) + "%"

Also conceivable that you'll have to do something with grdCalc.text. parseInt(grdCalc.text) or parseFloat(). I actually forget how JavaScript is going to handle that input otherwise.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
New Developer
Posts: 41
Registered: ‎02-11-2010
My Device: Bold 9000
My Carrier: AT&T

Re: math function round() makes label invisible...

Thanks!

New Developer
Posts: 41
Registered: ‎02-11-2010
My Device: Bold 9000
My Carrier: AT&T

Re: math function round() makes label invisible...

That did the trick! but Now I have to deal with some error handling... do you know how to implement the isNaN function?

 

I want to be able to display one message if the output is NaN. There is no option i can see that will display purely numbers on the keyboard, so i'm using the Pin input keyboard.

 

In javascript I know I can do something like

var my_string="This is a string";
if(isNaN(my_string)){
document.write ("this is not a number ");
}else{document.write ("this is  a number ");
}

 but I don't know how to implement it on cascades.

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: math function round() makes label invisible...

Best to restrict the values in the input to begin with. Values 0-9, . and - (if negative is allowed)