Thanks:  0
Likes:  0
Dislikes:  0

1. ## Currency conversion function

Anyone have any code they want to share on currency conversion? I've got an app that downloads the currency conversion factor to the client where some client code takes the input, multiplies it by that factor, and posts all three values back to the server.

2. ## Re: Currency conversion function

Well, since everyone seems to be hoarding their wheels, I had to re-invent it myself. Looks pretty solid to me, but if I missed some logic here please let me know.
<font class="small">Code:</font><hr /><pre>
function ConvertCurrency(fAmtInput: float;fConversionRate:float):string
var
fsCents,fsCentsTemp : string(3);//used for rounding step
fnumG :number;
fnumGtemp :float;
begin
fnumGtemp := (fAmtInput * fConversionRate)+0.006;
fnumG := number(fnumGtemp);
fsCentsTemp := Strstr(string(fnumGtemp),".");
Substr(fsCentsTemp, fsCents, 2,2);
ConvertCurrency := string(fnumG)+"."+ fsCents;
end ConvertCurrency;
</pre><hr />

3. ## Re: Currency conversion function

What is the +0.006 for?

4. ## Re: Currency conversion function

that would be for rounding
Zenpadre is just cutting off the decimal places he don't need, so if he first add this number, it will round it

but why 0.006?
i would expect 0.005

this way 4.354 will round up to 4.36

5. ## Re: Currency conversion function

[ QUOTE ]
that would be for rounding
Zenpadre is just cutting off the decimal places he don't need, so if he first add this number, it will round it

but why 0.006?
i would expect 0.005

this way 4.354 will round up to 4.36

[/ QUOTE ]

That's what I was asking.... I don't get why its 0.006, I also hate seeing magic numbers in code, prefer to create variables and assign values to them.....

6. ## Re: Currency conversion function

Yeah, I changed it to 0.005 I tried .006 because I actually found some cases where the client app and my function didn't align when I used .005, and I posted this before I had the final version (as if there is ever REALLY a final version). As for 'magic' numbers, in this situation I don't agree as it's not something that's going to change once it's set. If it was a value that might change in different test scenarios, then I'd agree.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.