package com.commerzinfo.util;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.Locale;

public final class DecimalFormatUtil {
    //Numberformat 2.091,56+ or 100,00-
    private static final DecimalFormat HTML_FORMAT = (DecimalFormat) DecimalFormat.getInstance(Locale.GERMAN);
    private static final DecimalFormat CSV_FORMAT = (DecimalFormat) DecimalFormat.getInstance(Locale.GERMAN);

    static {
        HTML_FORMAT.setNegativePrefix("");
        HTML_FORMAT.setNegativeSuffix("-");
        HTML_FORMAT.setPositiveSuffix("+");
        HTML_FORMAT.setParseBigDecimal(true);

        CSV_FORMAT.setNegativePrefix("-");
        CSV_FORMAT.setParseBigDecimal(true);
    }

    private DecimalFormatUtil() {
    }

    public static Number parse(String source, Mode mode) throws ParseException {
        if (Mode.HTML.equals(mode))
            return HTML_FORMAT.parse(source);
        else if (Mode.CSV.equals(mode))
            return CSV_FORMAT.parse(source);
        else
            return null;
    }

    public enum Mode {
        HTML,
        CSV
    }
}

@@ -851,32 +851,34 @@
 ML.equals(mode))
+ %7B
 %0A            ret
@@ -911,24 +911,26 @@
 ce);%0A       
+ %7D
  else if (Mo
@@ -949,16 +949,212 @@
 s(mode))
+ %7B%0A            //some rows have a pos prefix some dont. so just remove it for every row%0A            if (source.contains(%22+%22)) %7B%0A                source = source.replaceAll(%22%5C%5C+%22, %22%22);%0A            %7D
 %0A       
@@ -1198,21 +1198,25 @@
 %0A       
+ %7D
  else
+ %7B
 %0A       
@@ -1233,16 +1233,26 @@
 n null;%0A
+        %7D%0A
     %7D%0A%0A 

remove + sign for csv in any case to avoid numberformat-errors