I suppose many will not agree totally with my method, but I am happy with it. What I do is to simply store the value as an Integer - which means that $3.55 will be 355 in the table.
The application side then deals with all the rest.
The only reason is that you can manipulate Integers easier then other data types, and is easier portable accross many programming languages. I use Perl most of the time, and I have a simple routine to convert the integer into it's relevant currency:
Code:
sub cconvert {
# use: cconvert( 'integer', 'currency-symbol' );
# integer => integer value of the currency in cents
# currency-symbol => the string representation of the currency
if ( $_[0] && $_[1] ) {
my $tval = $_[1] . ( $_[0] / 100 );
return $tval;
} else {
# error
return -9999;
}
}
And here is a sample use:
Code:
1 #!/usr/bin/perl
2
3 $value = cconvert( '655', '$' );
4 if ( $value =~ /^-9999$/ ) {
5
6 # an error has occured - deal with it
7
8 } else {
9
10 print "$value\n";
11
12 }
13
14 $value = cconvert( '777' );
15 if ( $value =~ /^-9999$/ ) {
16
17 # an error has occured - deal with it
18
19 } else {
20
21 print "$value\n";
22
23 }
24
25 exit;
26
27 sub cconvert {
28
29 # use: cconvert( 'integer', 'currency-symbol' );
30 # integer => integer value of the currency in cents
31 # currency-symbol => the string representation of the currency
32
33 if ( $_[0] && $_[1] ) {
34
35 my $tval = $_[1] . ( $_[0] / 100 );
36 return $tval;
37
38 } else {
39
40 # error
41 return -9999;
42
43 }
44
45 }
I work exclusively ( at this stage ) with currencies that make use of cents ( decimal ) and where the currency symbol is in front, so I don't need to over complicate things.
Cheers