Hey, I am trying to code a battery bar in the my battery icon using the rounded rectangle. My current problem is that for some reason unless I turn the battery to 100%, it shows nothing instead of what I wanted it to show. Here's the code related to the bar:
var pwr = System.getSystemStats().battery+.5; var batStr = Lang.format( "$1$", [ pwr.format( "%2d" ) ] ); var BatteryBarLenght; var batInt; batInt=batStr.toNumber(); BatteryBarLenght=batInt/100*51; dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT); dc.drawRoundedRectangle(192, 56, 51, 28, 4); dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT); dc.fillRoundedRectangle(192, 56, BatteryBarLenght, 28, 4);
The 51 is the amount of pixels length I want for 100% battery in case it wasn't clear.\
Can you help me please finding the problem?
TY in advance!
EDIT: I found the problem. Because of the fix I made with the 0.5% it is now a float and not a number. I changed it toFloat and it worked fine! I leave the question open in case anyone else will have the problem I've experienced.