I’m trying to convert dollar amounts from a text file to a stored numeric type (therefore ‘String’ to float,BigDecimal,etc)
Problem is that some of the strings include commas: 1,270.00, 22,835.22, etc and return a “java.lang.NumberFormatException:” when trying to be converted.
String GrossEarnings = null; GrossEarnings = br.readLine(); float GE = Float.parseFloat(GrossEarnings); String GrossEarnings = null; GrossEarnings = br.readLine(); BigDecimal GE = new BigDecimal(GrossEarnings);
Is there a way to convert a String of numbers with commas to a numeric type? Or do the commas have to be removed?