Subject: | Better value for very small currency exchange rates |
Some currency exchange rates have almost no precision because the rate
is so small and Yahoo only reports 4 or 5 digits after the decimal point
no matter how small the rate is. For example
1 krw = 0.0009 usd
The attached patch changes Quote.pm so that rates like this are computed
using the reciprocal of the inverse rate so instead you get
1 krw = 0.00089656 usd
Subject: | currency2.diff |
--- lib/Finance/Quote.pm 2012-02-05 00:51:04.000000000 -0500
+++ lib/Finance/Quote.pm 2012-02-05 00:51:39.000000000 -0500
@@ -300,6 +300,22 @@
my $primary_rate = primary_url($this, $from, $to);
my $secondary_rate = secondary_url($this, $from, $to);
+
+ # If the rate is very small we get no accuracy so take the reciprocal
+ # of the inverse rate.
+ if ( $primary_rate && $primary_rate < .001 ) {
+ $primary_rate = 1 / primary_url($this, $to, $from);
+ if ( $primary_rate ) {
+ $primary_rate = int($primary_rate * 100000000 + .5) / 100000000;
+ }
+ }
+ if ( $secondary_rate && $secondary_rate < .001 ) {
+ $secondary_rate = 1 / secondary_url($this, $to, $from);
+ if ( $secondary_rate ) {
+ $secondary_rate = int($secondary_rate * 100000000 + .5) / 100000000;
+ }
+ }
+
my $exchange_rate = $primary_rate;
if ( $primary_rate && $secondary_rate ) {