Currencies not accepting my input correctly

Open to all! Ask other shopowners for help.
Post Reply
Moxamint
Member
Posts: 93
Joined: Fri Nov 06, 2020 10:36 am
Phoenix Version:
Has thanked: 33 times
Been thanked: 3 times

Currencies not accepting my input correctly

Post by Moxamint »

Hi All,

My bank provided me with a chart of currency exchange rates. I don't use the source that Phoenix Cart provides. Each currency value in my chart has only four decimal places instead of 8. For example, the exchange rate USD:EUR = 1:0.8748. My question is: when I entered 0.8748000 as the EUR value, why does it always turn out something like 0.87480003, not exactly 0.87480000?

Many thanks in advance for your help.

Eddy


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Currencies not accepting my input correctly

Post by ecartz »

It's because the floating point values traditionally used don't handle precision well. You'd probably be able to see the same problem with eight digits. It's just more obvious with replacing the trailing zeroes and with you entering the values manually.

This shouldn't actually be a problem generally, because the rounding should make the difference disappear. Because I don't know of a currency that actually has eight digits of precision. So you'd have to be selling at least a few thousand to notice even with four digits of precision. And more the less precision your currency has.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply