Esempio

public static void main( String[] args) {
String strShort = "125-"; // 125- is -125 in locale ar_EG //$NON-NLS-1$
try {
System.out.println( Short.parseShort(strShort) );
}catch (Exception e){
// NumberFormatException
e.printStackTrace();
System.out.println( e.getMessage() );
}
}

Soluzione
Usare
  • java.text.NumberFormat.parse (java.lang.String)

public static void main(String[] args){
java.util.Locale loc = new Locale("ar", "AE"); //$NON-NLS-1$ //$NON-NLS-2$
String strShort = "125-"; //$NON-NLS-1$

try {
short data = java.text.NumberFormat.getNumberInstance(loc).parse(strShort).shortValue();
System.out.println(data);
}catch (Exception e){
System.out.println(e.toString());
}
}

Soluzione
Usare ICU 2.6.1
  • com.ibm.icu.text.NumberFormat.parse (java.lang.String)

public static void main(String[] args){
java.util.Locale loc = new Locale("ar", "AE"); //$NON-NLS-1$ //$NON-NLS-2$
String strShort = "125-"; //$NON-NLS-1$

try {
short data = com.ibm.icu.text.NumberFormat.getNumberInstance(loc).parse(strShort).shortValue();
System.out.println(data);
}catch (Exception e){
System.out.println(e.toString());
}
}