How do you send currency amounts for localization?

Yametazamwa mara 71
Ruka hadi kwenye ujumbe wa kwanza ambao haujasomwa

jim lee

hayajasomwa,
12 Mei 2017, 12:14:4612/05/2017
kwa API Craft
As it appears there really is nocurrency standard, curious if anyone has had experience sending currency amounts that may be able to be localized via front-end.

Paypal/Stripe sends as non-decimal but not sure if that has any gotchas

E.g. sending a response balance of $100.00 would be sent as:
...
"currencyCode" : "USD", 
"balance" : 10000,
...

thoughts?

Hassan Schroeder

hayajasomwa,
12 Mei 2017, 18:13:2812/05/2017
kwa api-...@googlegroups.com
On Fri, May 12, 2017 at 9:14 AM, jim lee <jim...@gmail.com> wrote:

> Paypal/Stripe sends as non-decimal but not sure if that has any gotchas
>
> E.g. sending a response balance of $100.00 would be sent as:
> ...
> "currencyCode" : "USD",
> "balance" : 10000,

It seems intrinsically problematic to label something US "Dollars"
and then send a value as something else, e.g. "cents".

Creating unnecessary conversion interfaces -- um, why?

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote

Finn Neuik

hayajasomwa,
14 Mei 2017, 10:18:4614/05/2017
kwa API Craft
The 'USD' is the currency's ISO 4217 code https://en.wikipedia.org/wiki/ISO_4217 it's not really 'dollars' if that makes any sense. Note that not all currencies have 2 decimal places (the 'exponent').

The most likely reasons for them to to present the values using in minor units (cents in this case) are:
  • To remove any ambiguity over if fractional amounts are allowed (which might be supported in some situations).
  • If the values are treated as binary floating point numbers rather than decimal floating point numbers then summing lots of them can/will result in rounding issues (http://www.drdobbs.com/floating-point-summation/184403224). Treating them as integral values removes this possibility.
It's not unusual to see currency values represented like this in financial systems. It'll depend on the context if the above considerations apply or not. If not, the potential confusion might mean a more intuitive decimal + currency code is the way to go.

Hassan Schroeder

hayajasomwa,
14 Mei 2017, 10:40:0914/05/2017
kwa api-...@googlegroups.com
On Sun, May 14, 2017 at 7:18 AM, Finn Neuik <fin...@gmail.com> wrote:

> The most likely reasons for them to to present the values using in minor
> units (cents in this case) are:

...entirely bogus.

Describing dollar amounts in cents doesn't mean you'll never have
fractional values (via e.g. discounts, taxes), so -- no.

Use a Decimal datatype that *obviously and intuitively* represents
the currency in question and be done with it.

mca

hayajasomwa,
14 Mei 2017, 10:51:1814/05/2017
kwa api-...@googlegroups.com
when *sending* currency values, there is no "currency type" -- it's a message. however types exist on either end of the message (e.g. client and server). 

when i send currency values, i indicate the ISO value and represent the amount w/ as many decimal places necessary to be accurate (in USD it if common for values to have 3, 4 or more places after the decimal point).

"currency" : {"iso" : "USD", "value" : "1234.456"}
<money iso="COP">3605438.61</money>
etc...

the API docs encourage developers on either end of the message of use whatever local strong types their programming language provides and to NEVER assume the person on the "other end" of the message is using the same strong typing system. 

a few times, i've offered API consumers the option of negotiating for a particular currency ("can you send that in colombian pesos, please?") but it was usually a real hassle and I rarely do it now. I just book all stored currency values in a single ISO category and let clients deal with the conversions.



 
--
You received this message because you are subscribed to the Google Groups "API Craft" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-craft+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/api-craft.
For more options, visit https://groups.google.com/d/optout.

Finn Neuik

hayajasomwa,
14 Mei 2017, 11:28:5614/05/2017
kwa api-...@googlegroups.com
It depends on the context, for some representations it will be true, for others not. I'm not familiar with the Stripe API but if they've made that choice then it's likely due to the inability to make authorisations in fractional cents or to pay funds into accounts using fractional cents. A retail banking system calculating interest on a daily basis on small sums will use a much higher precision. It all depends...

Peter Williams

hayajasomwa,
5 Jun 2017, 16:34:5905/06/2017
kwa api-...@googlegroups.com
Have you considered <http://schema.org/MonetaryAmount>? Example:

    "balance": {
      "@type": "MonetaryAmount",
      "value": "100",
      "currency": "USD"
    },

Peter


Jibu wote
Mjibu mchapishaji
Sambaza
Ujumbe 0 mpya