Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Formatting MS Access Currency Values

by gryphon (Abbot)
on Apr 23, 2002 at 15:39 UTC ( [id://161342]=note: print w/replies, xml ) Need Help??


in reply to Formatting MS Access Currency Values

Greetings DaWolf,

I pulled a lot of this from the Perl Cookbook. Essentually, it's just adding the commas as normal then swapping the comma a period. Depending on your needs for currency, you may want to keep the "sprintf" rounding to round off numbers to two decimal places (like the last element of @data).

#!/usr/bin/perl -w use strict; my @data = ( '36000.0000', '12725.0000', '80000', '8123.2412' ); sub fix_number { my $number = shift; $number = reverse sprintf("%.2f", $number); $number =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; $number =~ tr/.,/,./; return scalar reverse $number; } foreach (@data) { print fix_number($_), "\n"; } exit;

-gryphon
code('Perl') || die;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://161342]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (1)
As of 2024-04-25 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found