title: What is the standard for formatting currency values in JSON?
body: <p>Bearing in mind various quirks of the data types, and localization, what is the best way for a web service to communicate monetary values to and from applications? Is there a standard somewhere?</p>
  
  <p>My first thought was to simply use the number type. For example</p>
  
  <pre><code>"amount": 1234.56
  </code></pre>
  
  <p>I have seen many arguments about issues with a lack of precision and rounding errors when using floating point data types for monetary calculations--however, we are just transmitting the value, not calculating, so that shouldn't matter.</p>
  
  <p><a href="http://culttt.com/2014/05/28/handle-money-currency-web-applications/">EventBrite's JSON currency specifications</a> specify something like this:</p>
  
  <pre><code>{
  "currency": "USD", 
  "value": 432, 
  "display": "$4.32"
  }
  </code></pre>
  
  <p>Bravo for avoiding floating point values, but now we run into another issue: what's the largest number we can hold?</p>
  
  <p><a href="https://groups.google.com/forum/#!topic/api-craft/jwnVh9TJyVw">One comment</a> (I don’t know if it’s true, but seems reasonable) claims that, since number implementations vary in JSON, the best you can expect is a 32-bit signed integer. The largest value a 32-bit signed integer can hold is 2147483647. If we represent values in the minor unit, that’s $21,474,836.47. $21 million seems like a huge number, but it’s not inconceivable that some application may need to work with a value larger than that. The problem gets worse with currencies where 1,000 of the minor unit make a major unit, or where the currency is worth less than the US dollar.  For example, a Tunisian Dinar is divided into 1,000 milim. 2147483647 milim, or 2147483.647 TND is $1,124,492.04. It's even more likely values over $1 million may be worked with in some cases. Another example: the subunits of the Vietnamese dong have been rendered useless by inflation, so let’s just use major units. 2147483647 VND is $98,526.55. I’m sure many use cases (bank balances, real estate values, etc.) are substantially higher than that. (EventBrite probably doesn’t have to worry about ticket prices being that high, though!)</p>
  
  <p>If we avoid that problem by communicating the value as a string, how should the string be formatted? Different countries/locales have drastically different formats—different currency symbols, whether the symbol occurs before or after the amount, whether or not there is a space between the symbol and amount, if a comma or period is used to separate the decimal, if commas are used as a thousands separator, parentheses or a minus sign to indicate negative values, and possibly more that I’m not aware of.</p>
  
  <p>Should the app know what locale/currency it's working with, communicate values like</p>
  
  <pre><code>"amount": "1234.56"
  </code></pre>
  
  <p>back and forth, and trust the app to correctly format the amount? (Also: should the decimal value be avoided, and the value specified in terms of the smallest monetary unit? Or should the major and minor unit be listed in different properties?)</p>
  
  <p>Or should the server provide the raw value and the formatted value?</p>
  
  <pre><code>"amount": "1234.56"
  "displayAmount": "$1,234.56"
  </code></pre>
  
  <p>Or should the server provide the raw value and the currency code, and let the app format it?
      "amount": "1234.56"
      "currencyCode": "USD"
  I assume whichever method is used should be used in both directions, transmitting to and from the server.</p>
  
  <p>I have been unable to find the standard--do you have an answer, or can point me to a resource that defines this? It seems like a common issue.</p>