Greetings.

I'm working with an app that interacts with (ugh!) MS Access and I'm doing a lot of queries in 'Currency' type fields.

When I ask for one of this values, this is the "normal" MS Access behaviour:

I ask for the value in the "account" field.

MS Access returns: 360000
What I want is: 360.000,00


So, I've wrote a sub to to this formatting for me. Here it is:
sub FormatValue { $c = 0; $vl = $_[0]; if ($vl ne "0,00" and $vl ne "0" and $vl ne ",00" and $vl ne ".0000") { if ($vl =~ m/(\.0000)/) { $vl =~ s/(\.0000)$/,00/; } else { $vl .= ",00"; } ($interessa,$zeros) = split (",",$vl); $compr = length $interessa; $c = int ($compr / 3); if ($c eq 1 and $compr > 3) { $um = substr($interessa, -3, 3); $interessa =~ s/$um/\.$um/; } elsif ($c eq 2) { $um = substr($interessa, -6, 3); $dois = substr($interessa, -3, 3); $interessa =~ s/$um/$um\./; } $result = $interessa.",".$zeros; } else { $result = "0,00"; } return $result; }
So, it works pretty fine:

Value of AccessReturned by sub
36000.000036.000,00
12725.000012.725,00


But when I get a value like 80000 it returns 8.0000,00 !

Anyone can tell me what's the catch here?

Thanks in advance,

Er Galvão Abbott
a.k.a. Lobo, DaWolf
Webdeveloper

In reply to Formatting MS Access Currency Values by DaWolf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.