02-21-2013 02:46 PM
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
Solved! Go to Solution.
02-21-2013 03:38 PM
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.
02-21-2013 03:45 PM
02-21-2013 05:00 PM
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;
02-21-2013 05:18 PM
ok. i try this... and comment.. Thanks for Reply
02-21-2013 06:26 PM
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.
02-21-2013 06:50 PM - edited 02-21-2013 07:10 PM
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
02-21-2013 07:33 PM
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); }