java - How to store 0.0001352? -


i have class has double 'sizeinmegs' variable , whenever value tiny, 0.00025 megs, stores 0.0 seen in debug watch.

how save in decimal glory?

here's code:

        thepdf.setfilesizeinmegabytes((thefile.length() / 1000000)); //that's double          double size = thefile.length(); // returns 12345         size = size / 1000000; returns 0.012345         double storedvalue = thepdf.getfilesizeinmegabytes(); // shows 0.0 in watch window          string value;         value = fmt(size); //this shows right value in string          lbltest.settext("size: " +  value + " mb");    ....  public static string fmt(double d) {     if(d == (int) d)         return string.format("%d",(int)d);     else         return string.format("%s",d); } 

you should use bigdecimal instead of double, way won't lose precision. can show code in:

thepdf.setfilesizeinmegabytes() 

and

thepdf.getfilesizeinmegabytes() 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

django - CSRF verification failed. Request aborted. CSRF cookie not set -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -