Doing math on regex replace match variable (%1)
<p>My csv files contain percentage values <strong>with</strong> percent signs (yuck). I want to pull the %'s out and multiply the values by 0.01 so I can store it as a proper decimal. </p>

<p>At first I thought I'd split it up and do it in two steps:</p>

<ul>
<li>remove the %'s</li>
<li>do math on the remaining values</li>
</ul>

<p>But that's needlessly complicated, right? It gets me into trouble with values that weren't percents to begin with but look like them after removing the %'s (starting to think like a regex guy).  I'm sure can do this in one regex replace.</p>

<p>I puzzled out a regex to find the values, but now I'm trying to do math on my replacement value and I'm running into trouble with using $1. I can't seem to get it to multiply by 0.01. I've tried a bunch of parentheses and [decimal] declarations, but can't get it to work.</p>

<p>Example of existing file:</p>

<pre><code>1.9500%, 123.23, 0.0123%, "textvalue", 2.1450%, 2.89
</code></pre>

<p>Example of desired file (percent signs removed and math complete). The leading/trailing zeroes are included for clarity, but I don't technically need them:</p>

<pre><code>0.019500, 123.23, 0.000123, "textvalue", 0.021450, 2.89
</code></pre>

<p>Here's my code:</p>

<pre><code>$Files = Get-ChildItem *input.csv
foreach ($file in $Files)
    {
        $file |
        Get-Content | #assume that I can't use -raw
        % {$_ -replace '(\d+\.\d+)%', ("`$1" * 0.01)} | #THIS is my problem
        out-file output.csv -append -encoding ascii
    }
</code></pre>