<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.outsightinteractive.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>Outsight Interactive - Getting VBScript to Correctly Interpret Number Formats Across Locales - Comments</title>
 <link>http://www.outsightinteractive.com/blog/getting_vbscript_to_correctly_interpret_number_formats_across_locales</link>
 <description>Comments for &quot;Getting VBScript to Correctly Interpret Number Formats Across Locales&quot;</description>
 <language>en</language>
<item>
 <title>Getting VBScript to Correctly Interpret Number Formats Across Locales</title>
 <link>http://www.outsightinteractive.com/blog/getting_vbscript_to_correctly_interpret_number_formats_across_locales</link>
 <description>&lt;h3&gt; The Setup &lt;/h3&gt;
&lt;p&gt;
You have a double formatted as a string with the decimal part separated from the whole part by a full-stop, e.g. &lt;code&gt;&quot;1234.9&quot;&lt;/code&gt;. Of course, &lt;a href=&quot;http://blogs.msdn.com/oldnewthing/archive/2006/04/17/577483.aspx&quot;&gt; not all cultures separate their digits the same way&lt;/a&gt;, and in fact, the site you&#039;re working on has a locale setting for a locale that uses a comma to separate the integer from the decimal, and vice-versa, e.g. German:&lt;code&gt;&quot;1.234,9&quot;&lt;/code&gt; or French &lt;code&gt;&quot;1 234,9&quot;&lt;/code&gt; style digit grouping. For the sake of argument, let&#039;s also say the decimal number is being parsed out of an XML file input by a US or UK user and that a full-stop is meant to separate the whole and fractional parts of the number.
&lt;/p&gt;
&lt;h3&gt; The Problem &lt;/h3&gt;
&lt;p&gt;
ASP/VBScript&#039;s clever and useful &lt;code&gt;FormatNumber&lt;/code&gt; and &lt;code&gt;FormatCurrency&lt;/code&gt; functions which solve oh-so-many related problems are no help:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
SetLocale(&quot;de-DE&quot;)
&#039;This is what we want (notice no quotes below)
FormatNumber(1234.9) &#039;-&amp;gt; 1.234,90

&#039;This is what we get (when using a string)
FormatNumber(&quot;1234.9&quot;) &#039;-&amp;gt; 12.349,00
FormatCurrency(&quot;1234.9&quot;) &#039; -&amp;gt; 12.349,00 €
&#039;ARGH!
&lt;/pre&gt;&lt;p&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;When in a German locale, &lt;code&gt;FormantNumber&lt;/code&gt; sees the string &lt;code&gt;&quot;1234.9&quot;&lt;/code&gt;, it assumes that the full-stop is merely a misplaced thousands separator and drops it. Though I was confused and angry at this behavior at first, I have come to see the sense that it makes (consider interpreting &lt;code&gt;&quot;1.234&quot;&lt;/code&gt; in a German locale).
&lt;/p&gt;&lt;span class=&quot;readmore&quot;&gt;&lt;a href=&quot;/blog/getting_vbscript_to_correctly_interpret_number_formats_across_locales&quot; title=&quot;Read more on this article&quot;&gt;read more...&lt;/a&gt;&lt;/span&gt;</description>
 <comments>http://www.outsightinteractive.com/blog/getting_vbscript_to_correctly_interpret_number_formats_across_locales#comment</comments>
 <category domain="http://www.outsightinteractive.com/blog/tags/asp">ASP</category>
 <category domain="http://www.outsightinteractive.com/blog/tags/development">Development</category>
 <category domain="http://www.outsightinteractive.com/blog/tags/hacks">Hacks</category>
 <category domain="http://www.outsightinteractive.com/blog/tags/internationalization">Internationalization</category>
 <pubDate>Mon, 02 Apr 2007 11:34:48 -0400</pubDate>
 <dc:creator>Brandon</dc:creator>
 <guid isPermaLink="false">44 at http://www.outsightinteractive.com</guid>
</item>
</channel>
</rss>

