private static double getNumber(FldSimpleModel model, String value) throws FieldResultIsNotANumberException { WordprocessingMLPackage pkg = model.getWordMLPackage(); String decimalSymbol = null; if (pkg != null && pkg.getMainDocumentPart().getDocumentSettingsPart() != null) { DocumentSettingsPart docSettingsPart = pkg.getMainDocumentPart().getDocumentSettingsPart(); if (docSettingsPart.getJaxbElement().getDecimalSymbol() != null) { decimalSymbol = docSettingsPart.getJaxbElement().getDecimalSymbol().getVal(); } } // For DOCPROPERTY field, and possibly some others, but not "=", // Word will parse "€180,000.00 EUR" as a number if (model.fldName.equals("DOCPROPERTY") || model.fldName.equals("MERGEFIELD")) { // First, parse the value NumberExtractor nex = new NumberExtractor(decimalSymbol); try { value = nex.extractNumber(value); } catch (java.lang.IllegalStateException noMatch) { // There is no number in this string. // In this case Word just inserts the non-numeric text, // without attempting to format the number throw new FieldResultIsNotANumberException("No number in " + value); } } try { return Double.parseDouble(value); } catch (Exception e) { // TODO: is it a bookmark? throw new FieldResultIsNotANumberException(); } }