Why are some JSON response values strings instead of numbers?

Below is (part of) the response when I make an API call to get my account info. Why are fields like “buying_power”, “portfolio_value”, “equity”, etc returned as string values instead of an actual number type? This would make working with these responses so much easier in strongly typed languages like Swift.

    "daytrade_count": 0

yassck02, i don’t mean to be rude but why would you even ask a question like this? That’s the way it is, they not gonna change it for you anyways. Just code to the spec and move on

I already coded to the spec so I was really asking out of curiosity - and also to suggest an enhancement for v3 :slight_smile:

It just seems odd that they chose to require everyone that adopts this API to manually convert the value to a number before they use it in any sort of calculation. I was wondering if anyone had any insight into this decision

Well the main reason I can think of is that different programming languages handle big/small numbers and decimal in different ways if they are out of range or simply very big or very small. They may have did it for consistency. I might have read something like this in their docs but forgot where.

The decision to represent most numbers in the trading APIs as strings was primarily for consistency and accuracy across different SDKs and languages. As @rockbusiness mentioned, different languages handle numbers differently. Sometimes numbers can be automatically (and unintentionally) rounded, truncated, or represented with more precision than actually present. Using strings, one must explicitly translate the value into a number and, presumably, provide the intentioned representation. That is pretty much it.