title: Looking for a better way of manipulating a numeric string that contains delimiters
body: <p>I need to verify and manipulate a numeric string. In this example, I have this string <code>&quot;1.59945,5|10&quot;</code>. The <code>&quot;,&quot;</code> and <code>&quot;|&quot;</code> are delimiters, so it has three separate values: <code>1.59945</code>, <code>5</code> and <code>10</code>. I want to round off any float values (In this case <code>1.59945</code>) to the nearest 2 decimal places before saving the entire string back to the database. The result should be <code>&quot;1.60,5|10&quot;</code>.</p>
  <p>Here's the <a href="http://jsfiddle.net/lau_chung/tkxp62vn/14/" rel="nofollow noreferrer">JsFiddle</a></p>
  <pre><code>let values = &quot;1.59945,5|10&quot;
  const separators = values.split(&quot;&quot;).filter(v=&gt;{
    return v === &quot;,&quot; || v=== &quot;|&quot;
  })
  
  const regex = new RegExp(`,|\\|`);
  values = values.split(regex).map(value=&gt;{
     if (value.includes(&quot;.&quot;)) {
        return parseFloat(value).toFixed(2)
     } else {
        return value;
     }
  }).join(&quot;,&quot;)
  separators.forEach(separator=&gt;{
     values = values.replace(&quot;,&quot;,separator)
  })
  console.log(values)
  </code></pre>
  <p>The code seems to achieve what I want, but is there a more concise / better way of doing it?</p>