title: Faster replacement of parseFloat(String str.replace("," , ".")) in case of decimal numbers
body: <p><strong>Brief description:</strong></p>
  <p>I´ve build up a &quot;reinvention-of-the-wheel&quot; solution for parsing <code>Strings</code> with decimal number values to <code>Float</code> Objects. Basically i´ve read some data from various HTML tables as <code>String</code> Objects and parsed 2 <code>Strings</code> of every <code>htmlTableRow</code> into numeric values, e.g: (<code>String str = &quot;13,404&quot;</code>).</p>
  <p>I ended up using <code>str.replace(&quot;,&quot; , &quot;.&quot;)</code> due to <code>NumberFormatException</code> on every single value and i ask myself, if there are any useful Java libraries for this use case.</p>
  <p>How can a &quot;best of practice solution look like?&quot; <em><strong>OR</strong></em> <br>&quot;What can be done better / easier&quot; in terms of reducing code and decreasing the execution time.</p>
  <p><em>I created the ListValuedMaps essentially to subcategorize the data later (according to other criteria).</em></p>
  <p><strong>Java code (Eclipse):</strong></p>
  <pre><code>import java.io.*;
  import org.jsoup.Jsoup;
  import org.jsoup.nodes.Document;
  import org.jsoup.select.Elements;
  import java.util.*;
  
  import org.apache.commons.collections4.ListValuedMap;
  import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
  
  
  public class Webdata {
      
      public static void main(String[] args) throws IOException
          {
              long start = System.currentTimeMillis();
              
              parseData();
              
              System.out.println(secondsElapsed(start)+&quot; seconds processing time&quot;);
          };
              
      private static void parseData() throws IOException
          {
              
              List &lt;String&gt; subdirectories = new ArrayList&lt;&gt;();
              String chars = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;;
              
              String errorMessage1 = &quot;String formatting problem&quot;;
              String errorMessage2 = &quot;String object non existent&quot;;
              
              for (int i=0; i&lt; chars.length(); i++)
              {
                  subdirectories.add(&quot;https://www.tradegate.de/indizes.php?buchstabe=&quot;+chars.charAt(i));
              }
              
                  
              List &lt;String&gt; stockMetadata = new ArrayList&lt;&gt;();
              
              ListValuedMap &lt;String, List&lt;String&gt;&gt; nonError = new ArrayListValuedHashMap&lt;&gt;();
              ListValuedMap &lt;String, List&lt;String&gt;&gt; numFormatError = new ArrayListValuedHashMap&lt;&gt;();
              ListValuedMap &lt;String, List&lt;String&gt;&gt; nullPointerError = new ArrayListValuedHashMap&lt;&gt;();
          
              int cap1 = 44;
              int cap2 = 56;
      
              for (int suffix = 0; suffix &lt;chars.length(); suffix++) 
              {   
              Document doc = Jsoup.connect(subdirectories.get(suffix).toString()).get();
              Elements htmlTableRows = doc.getElementById(&quot;kursliste_abc&quot;).select(&quot;tr&quot;);
              
              htmlTableRows.forEach( tr-&gt; 
                      {
                      String stockName    = tr.child(0).text();
                      String bid_price    = tr.child(1).text();
                      String ask_price    = tr.child(2).text();
                      String numOrders    = tr.child(4).text();
                      String isin         = tr.child(0).selectFirst(&quot;a&quot;).absUrl(&quot;href&quot;).substring(cap1,cap2);
                      
                      try 
                      {
                          if (calcSpread(bid_price, ask_price) &lt; 12) 
                          {
                              Collections.addAll(stockMetadata, isin, bid_price, ask_price, calcSpread(bid_price, ask_price).toString());
                              nonError.put(stockName,stockMetadata);  
                              
                              System.out.printf(&quot;%-45s  %-10s  %-10s %-10s %n&quot;,
                                      stockName, bid_price, ask_price, calcSpread(bid_price, ask_price));
                          }
                          
                          else if (calcSpread(bid_price, ask_price) &gt; 12)
                          {
                              Collections.addAll(stockMetadata, isin, bid_price, ask_price, calcSpread(bid_price, ask_price).toString());
                              nonError.put(stockName,stockMetadata);  
                              
                              System.out.printf(&quot;%-45s  %-10s  %-10s %-10s %n&quot;,
                                      stockName, bid_price, ask_price, calcSpread(bid_price, ask_price));
                          }
                              stockMetadata.clear();
                              
                      }
                      catch (NumberFormatException e) 
                      {
                          Collections.addAll(stockMetadata, e.getMessage());
                          numFormatError.put(stockName, stockMetadata);
                          stockMetadata.clear();
                          
                          System.out.printf(&quot;%-45s  %-10s  %-10s %-10s %n&quot;,
                                  stockName, bid_price, ask_price, errorMessage1);
                      }
                      
                      catch (NullPointerException Ne) 
                      {
                          Collections.addAll(stockMetadata, Ne.getMessage());
                          nullPointerError.put(stockName, stockMetadata);
                          stockMetadata.clear();
                          
                          System.out.printf(&quot;%-45s  %-10s  %-10s %-10s %n&quot;,
                                  stockName, bid_price, ask_price, errorMessage2);
                          
                      }   //end of try-catch
                      
               });        //end of for-each loop htmlTableRows
          }               //end of JSOUP method
      }                   //end of main method
      
      
      public static Float calcSpread (String arg1, String arg2) 
      {
          try 
          {
              Float bid = Float.parseFloat(arg1.replace(&quot;,&quot; , &quot;.&quot;));
              Float ask = Float.parseFloat(arg2.replace(&quot;,&quot; , &quot;.&quot;));
              Float spread = ((ask-bid)/ask)*100;
              
              return spread;
          }
          catch (NumberFormatException e)
          {
              return null;
          }
      }
      
      public static Long secondsElapsed(Long start) {
          
          Long startTime = start;
          Long endTime = System.currentTimeMillis();
          Long timeDifference = endTime - startTime;
          
          return timeDifference / 1000;
      }
      
  }  //end of class
  </code></pre>
  <p><strong>Maven dependencies / pom.XML</strong></p>
  <pre><code>&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;TEST&lt;/groupId&gt;
    &lt;artifactId&gt;TEST&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    
    &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;maven.compiler.source&gt;1.7&lt;/maven.compiler.source&gt;
      &lt;maven.compiler.target&gt;1.7&lt;/maven.compiler.target&gt;
    &lt;/properties&gt;
    
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.jsoup&lt;/groupId&gt;
      &lt;artifactId&gt;jsoup&lt;/artifactId&gt;
      &lt;version&gt;1.11.3&lt;/version&gt;
    &lt;/dependency&gt;
    
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
      &lt;artifactId&gt;commons-collections4&lt;/artifactId&gt;
      &lt;version&gt;4.4&lt;/version&gt;
  &lt;/dependency&gt;
    
    &lt;dependency&gt;
      &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
      &lt;artifactId&gt;commons-lang3&lt;/artifactId&gt;
      &lt;version&gt;3.0&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
    &lt;build&gt;
      &lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.8.1&lt;/version&gt;
          &lt;configuration&gt;
            &lt;release&gt;18&lt;/release&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  <p><strong>Result:</strong></p>
  <pre><code>....
  Zincx Resources Corp.                          0,0666      0,084      20.714281  
  Zinnwald Lithium PLC                           0,109       0,125      12.800002  
  Zion Oil &amp; Gas Inc.                            0,1648      0,1758     6.2571063  
  Zions Bancorporation                           57,50       57,76      0.45013562 
  Zip Co. Ltd.                                   0,54        0,57       5.263153   
  ZipRecruiter Inc.                              17,66       18,165     2.7800772  
  Zivo Bioscience Inc.                           3,02        3,14       3.8216598  
  Zoetis Inc. CL A                               155,84      158,26     1.5291282  
  Zoom Video Communications Inc.                 78,08       79,12      1.3144602  
  Zoomd Technologies Ltd.                        0,22        0,24       8.333332   
  Zoomlion Heavy Ind.S.&amp;T.Co.Ltd                 0,379       0,4286     11.572563  
  Zovio Inc.                                     0,236       0,238      0.8403379  
  Zscaler Inc.                                   168,40      170,10     0.9994192  
  ZTE Corp.                                      2,092       2,158      3.0583868  
  ZTO Express (Cayman) Inc.                      27,40       28,20      2.8368835  
  ZTO Express (Cayman) Inc. ADRs                 25,80       27,60      6.521744   
  Zumtobel Group AG                              6,27        6,34       1.1041036  
  Zuora Inc. Class A                             7,722       7,888      2.104461   
  Zur Rose Group AG                              ./.         ./.        String object non existent 
  Zurich Insurance Group AG                      ./.         ./.        String object non existent 
  ZW Data Action Technolog. Inc.                 0,9788      1,0285     4.832277   
  Zylox-Tonbridge Medical Tech.                  1,19        1,26       5.5555506  
  Zymergen Inc.                                  2,607       2,6965     3.3191156  
  Zymeworks Inc.                                 5,578       5,698      2.1060002  
  Zynerba Pharmaceuticals Inc.                   1,0172      1,1212     9.275774  
  
  8 seconds processing time
  </code></pre>