Formatting a float will cause ArrayIndexOutOfboundException.
The following code will thorws exception for a specified number.
import java.util.*;
public class Test12 {
public static void main(String[] arg) {
try {
Float flt = 100000000.0F;
Float flt1 = 100000000000.0F;
float flt2 = 10000000000.0F;
Formatter formatter = new Formatter(System.out);
formatter.format( " floating point number in decimal is %5.2f and hexa decimal is %^<a %n",flt1);
formatter.format( " floating point number in decimal is %5.2f and hexa decimal is %^<a %n",flt);
formatter.format("number is "+flt2+"%5.2f decimal and %^<a %n ",flt2);
} catch(Exception exp) {
System.out.println(" Exception raised .. "+exp.getMessage());
exp.printStackTrace();
}
}
}
the console is as follows.
vishalb:/home/vv145429/tiger/src/formating/bugs 146 % javac -source 1.5 Test12.java
vishalb:/home/vv145429/tiger/src/formating/bugs 147 % java Test12
floating point number in decimal is 99999997952.00 and hexa decimal is 0X1.74876EP36
floating point number in decimal is 100000000.00 and hexa decimal is 0X1.7D784P26
number is 1.0E10 Exception raised .. null
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at sun.misc.FormattedFloatingDecimal.getChars(FormattedFloatingDecimal.java:974)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2934)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2859)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2844)
at java.util.Formatter$FormatSpecifier.printFloat(Formatter.java:2436)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2388)
at java.util.Formatter.format(Formatter.java:2165)
at java.util.Formatter.format(Formatter.java:2100)
at Test12.main(Test12.java:11)
vishalb:/home/vv145429/tiger/src/formating/bugs 148 %
The following code will thorws exception for a specified number.
import java.util.*;
public class Test12 {
public static void main(String[] arg) {
try {
Float flt = 100000000.0F;
Float flt1 = 100000000000.0F;
float flt2 = 10000000000.0F;
Formatter formatter = new Formatter(System.out);
formatter.format( " floating point number in decimal is %5.2f and hexa decimal is %^<a %n",flt1);
formatter.format( " floating point number in decimal is %5.2f and hexa decimal is %^<a %n",flt);
formatter.format("number is "+flt2+"%5.2f decimal and %^<a %n ",flt2);
} catch(Exception exp) {
System.out.println(" Exception raised .. "+exp.getMessage());
exp.printStackTrace();
}
}
}
the console is as follows.
vishalb:/home/vv145429/tiger/src/formating/bugs 146 % javac -source 1.5 Test12.java
vishalb:/home/vv145429/tiger/src/formating/bugs 147 % java Test12
floating point number in decimal is 99999997952.00 and hexa decimal is 0X1.74876EP36
floating point number in decimal is 100000000.00 and hexa decimal is 0X1.7D784P26
number is 1.0E10 Exception raised .. null
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at sun.misc.FormattedFloatingDecimal.getChars(FormattedFloatingDecimal.java:974)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2934)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2859)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2844)
at java.util.Formatter$FormatSpecifier.printFloat(Formatter.java:2436)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2388)
at java.util.Formatter.format(Formatter.java:2165)
at java.util.Formatter.format(Formatter.java:2100)
at Test12.main(Test12.java:11)
vishalb:/home/vv145429/tiger/src/formating/bugs 148 %