Tag Archives: number
18,700 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
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);
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
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);
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