Tag Archives: number

10,155 views

Round number float – double to int – long Java example

int nf = Math.round(5.789f); System.out.print(nf); // 6   float f = 28.611f; int n3 = Math.round(f); System.out.println(n3); // 29   double d = 1234.56; long lon = Math.round(d); System.out.println(lon); // 1235   int diff = 90 – 40; // float … Continue reading

Posted in Android Examples Code | Tagged , | Comments Off on Round number float – double to int – long Java example
3,784 views

Is NaN isNaN isInfinite number value Java Android example

float, double is NaN isNaN() isInfinite() Java Android example. float f = 0.f; boolean bIsNaN = Float.isNaN(f); boolean bIsInfinite = Float.isInfinite(f);   double d = Math.sqrt(-10); boolean b = Double.isNaN(d);

Posted in Android Examples Code, Bugs, warnings, errors | Tagged | Comments Off on Is NaN isNaN isInfinite number value Java Android example
24,336 views

Formatting a Number to String NumberFormat DecimalFormat locale Java Android example code

NumberFormat, DecimalFormat, format(), locale format Java Androidexample source code NumberFormat numberFormat = new DecimalFormat("##"); String str = numberFormat.format(-01234.567); // -1235 System.out.print(str + "\n");   str = numberFormat.format(00); // 0 System.out.print(str + "\n");   numberFormat = new DecimalFormat("##00"); str = numberFormat.format(0); … Continue reading

Posted in Android Examples Code | Tagged , , , , , | Comments Off on Formatting a Number to String NumberFormat DecimalFormat locale Java Android example code
5,630 views

Number convert int to string Java Android example code

Convert number int to string Android Java example source code. int n = 0;   try { n = Integer.parseInt("21")); } catch(NumberFormatException e) { System.out.println("Could not parse " + e); } // int to string String s = String.valueOf(24);

Posted in Android Examples Code, Array,List,Collections | Tagged , , , | Comments Off on Number convert int to string Java Android example code
6,569 views

Random number Java

Generate random number Android Java example source code. Random rand = new Random(); int i = rand.nextInt() % 256; // range -255 +255 System.out.print(i + "\n"); // -184 i = Math.abs(rand.nextInt() % 12); // range 0 +11 System.out.print(i); // 7 … Continue reading

Posted in Android Examples Code, Array,List,Collections | Tagged , , , , | Comments Off on Random number Java