1: clear all; 2: clc; 3: 4: % Prompt5: conv = input('Conversion Rate : ');
6: amt = input('Amount : ');
7: 8: % Synthetize range 9: amin = round(amt*0.95*100)/100; 10: amax = amt; 11: 12: range = amin:0.01:amax; 13: 14: % Find result after rounding 15: ay = floor(range*conv*100)/100; 16: 17: % Result without rounding 18: y = range*conv; 19: 20: % Differences 21: dy = y-ay; 22: 23: % Plot 24: subplot(2,1,1); 25: plot(range, y, range, ay); 26: subplot(2,1,2); 27: plot(range, dy); 28: 29: % Find minimum difference 30: [my i] = min(dy); 31: 32: % Result33: disp(['Best amount : ' num2str(range(i))]);
34: disp(['Result : ' num2str(y(i),10)]);
35: disp(['After conversion : ' num2str(ay(i),15)]);
36: disp(['Difference : ' num2str(dy(i),15)]);
When you’re dealing with Paypal, their conversion rates are usually 5 decimal places (e.g. 2.88145), but what they give you is 2 decimal places.
See the problem? 1 USD is originally RM2.88145, but they give you RM2.88 instead! Yes, they sucked out the RM0.00145 – this might not look a lot to you, but imagine they get RM0.00145 from 1 million people.
RM1450 into the pocket – for doing nothing at all! (after already robbing you by offering lower conversion rates)
This MATLAB script tries to limit your losses to the minimum.
Scenario
I have 429.33 USD, if I convert directly, I’ll get 1237.09 MYR instead of (1237.0929285 MYR), therefore losing 0.0029285 MYR.
Using the script, the best conversion amount is 423.45 USD, yielding 1220.15 MYR (instead of 1220.150003 MYR), therefore losing only 0.000003 MYR.
Excellent? If you haven’t notice, it’s 99.9% savings :D
Yes, I’m stingy =P