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

Java Development

Reply
New Contributor
Marthianfred
Posts: 6
Registered: ‎02-21-2013
My Device: 9810
My Carrier: movistar
Accepted Solution

dude Memory.getFlashFree()

Hello all...

 

i have one Questions

 

i use Memory.getFlashFree()... yes this retrun int... very well..

 

how to i can convert to mb

 

i make this

 

int ramfree = Memory.getFlashFree();
public static final long  MEGABYTE = 1048576L;

add(new LabelField(fm(ramfree / MEGABYTE) + "MB"));


this no retrun goob


the free space is 115,4 MB

this retrun 115,0MB i dont under strand any body can help me Thanks in advance

 

 

wthatsapp +584248144402
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: dude Memory.getFlashFree()

By default, Java will use integers for its arithmetic.  If you want it to return a floating point number you have to do the calaculations in a way that forces Java for use floating point.

Please use plain text.
New Contributor
Marthianfred
Posts: 6
Registered: ‎02-21-2013
My Device: 9810
My Carrier: movistar

Re: dude Memory.getFlashFree()

you cant show how to i can make this... Thanks
wthatsapp +584248144402
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: dude Memory.getFlashFree()

I recommend that you get a Java book.  It will show you things like this and other Java 'tricks' and will save you hours of frustration.

 

In this specific case something like the following will do it:

 

float ramfree = )float) Memory.getFlashFree();
public static final float MEGABYTE = 1048576f;

float megabytesFree = ramfree/MEGABYTE;

Please use plain text.
New Contributor
Marthianfred
Posts: 6
Registered: ‎02-21-2013
My Device: 9810
My Carrier: movistar

Re: dude Memory.getFlashFree()

ok. i try this... and comment.. Thanks for Reply

wthatsapp +584248144402
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: dude Memory.getFlashFree()

I am guessing the next question will be how to just have a fixed number of decimal points.  I think the following is the easiest way, but I suspect it is 'grubby'.  If you want two decimal points, then calculate the integer value that is 100 times too big, then convert to float and divided by 100 - meaning you will only ever have two decimal digits at most.  Might have fewer mind....

 

Anyway, let us know how you get on. 

Please use plain text.
New Contributor
Marthianfred
Posts: 6
Registered: ‎02-21-2013
My Device: 9810
My Carrier: movistar

Re: dude Memory.getFlashFree()

[ Edited ]

I have this code ...
I want to know exactly ... few MB free on the device ..

 

public static final float MEGABYTE = (Memory.getFlashFree()/1048576*100000)/100000 ;

add(new LabelField(fm(MEGABYTE) + " MB")); public String fm(double result) { Formatter formatter = new Formatter("en"); return formatter.formatNumber(result,1); }

This shows the decimal ... I do not understand is why do not I get the missing kb. example the device is free. 115.1

achievement is the result we need 115.0 accomplish this. can not be so complicated

wthatsapp +584248144402
Please use plain text.
New Contributor
Marthianfred
Posts: 6
Registered: ‎02-21-2013
My Device: 9810
My Carrier: movistar

Re: dude Memory.getFlashFree()

Ready..!!! i have solve. this..

 

Thanks for help

 

public static final float MEGABYTE = ((float)Memory.getFlashFree()/1048576*100000)/100000 ;

add(new LabelField(fm(MEGABYTE) + " MB")); public String fm(double result) { Formatter formatter = new Formatter("en"); return formatter.formatNumber(result,1); }
wthatsapp +584248144402
Please use plain text.