<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>mehblog: [snippet] Cleaning up currency strings</title>
    <link>http://blog.pauldalton.co.uk/articles/2006/01/18/snippet-cleaning-up-currency-strings</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>random mumblings</description>
    <item>
      <title>[snippet] Cleaning up currency strings</title>
      <description>&lt;p&gt;I was working on some data that I needed to import into mysql for a new rails project I&amp;#8217;ve started.&lt;/p&gt;


	&lt;p&gt;Some of the fields are currency strings, eg &#163;4,000.00. Now initially I was tempted to just bung them into the table as varchars but there is a good chance that at some point down the line I&amp;#8217;m going to want to &amp;#8216;do maths&amp;#8217; with these numbers so I really had to convert them to floats.&lt;/p&gt;


	&lt;p&gt;In the end I used this little bit of code which worked a treat:&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;return amount.gsub(/[&#163;,]/,&amp;#8217;&amp;#8216;)&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;So what this does is matches the characters &#163; and , and substitutes them with blank. Works a treat.&lt;/p&gt;</description>
      <pubDate>Wed, 18 Jan 2006 06:46:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:da073b29269d84a26bf737a59b487d90</guid>
      <author>paul</author>
      <link>http://blog.pauldalton.co.uk/articles/2006/01/18/snippet-cleaning-up-currency-strings</link>
      <category>Rails</category>
    </item>
  </channel>
</rss>
