M
M
mitaichik2015-12-07 15:56:30
PHP
mitaichik, 2015-12-07 15:56:30

How do you implement currency transactions?

Hello!
We have a class Money in the project, with the fields amount and currency.
Often there is a need to calculate something like (10 USD * $coefficient + 1000 RUB + 100 Euro) / 3
Now it all looks very inconvenient and with a huge bunch of extra code - on the spot we bring it to a single currency at the current rate, calculate, create a new Money with the result. ..
I want to ask how you solve such problems? Can you use any libraries?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-12-07
@mitaichik

you can make some kind of DSL using fluent interface, something like query builder etc. to make it easier to work with this stuff.
The most difficult thing will be to bring everything to one currency. And always work only with integers. I don’t know such ready-made libraries, and given the specifics, I don’t think that they are needed, it’s very specific. It is impossible to single out any common task other than currency conversion.

M
Mikhail Osher, 2015-12-07
@miraage

https://github.com/florianv/swap

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question