Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-37329

Bug in StatsMath.java DecimalFormat

XMLWordPrintable

      The implementation in statsmath.java results in an NumberFormatException when then LANG for the VM is set to another than EN:

      Caused by: java.lang.NumberFormatException: For input string: "19,16"
      at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
      at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
      at java.lang.Double.parseDouble(Double.java:538)
      at java.lang.Double.valueOf(Double.java:502)
      at jenkins.plugins.build_metrics.stats.StatsMath.roundTwoDecimals(StatsMath.java:13)
      at jenkins.plugins.build_metrics.stats.StatsMath.getPercent(StatsMath.java:8)
      at jenkins.plugins.build_metrics.stats.StatsFactory.getFailureRate(StatsFactory.java:167)
      ... 135 more

      Please change:
      public static double roundTwoDecimals(double iVal)

      { DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(iVal)); }

      to:
      public static double roundTwoDecimals(double iVal)

      { DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.getDefault()); DecimalFormat twoDForm = new DecimalFormat("#"+decimalFormatSymbols.getDecimalSeparator()+"##",decimalFormatSymbols); return Double.valueOf(twoDForm.format(iVal)); }

      Thanks

            px3 Rolf Rother
            px3 Rolf Rother
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: