4 ms·
> Send numbers as string [...] Why? Why not send a number as number (double) and treat it as hostile in the backend? I dislike sending numbers as string becaus
by chrisandchris 6y ago
> Send numbers as string [...]
Why? Why not send a number as number (double) and treat it as hostile in the backend? I dislike sending numbers as string because I think the different data types exist for a reason.
- e12e 6y agoOne reason could be that it's easy to think that a "number" is sanely typed, while you almost never want a double - not for quantity, not for price, etc. So you're going to cast to some (big) integer anyway...
- Kwpolska 6y agoIn languages with reasonable number types (i.e. not JS), the parsers are typically able to produce integers, or even BigDecimal, out of a JSON number, without going through double.
- e12e 6y agoI guess I feel returning error invalid integer for a valid json double is a bit wierd - but I guess it's not technicallyaany worse than "could not parse string as integer. It's more that it is expected that strings hold" other" data, like timestamps, while one might expect a double to hold only (but also any) doubles.
- ehutch79 6y agoI don't care if you like it or not, if your numbers are actually that large, serialize it to a string and back out on your backend. You shouldn't be blindly dumping json to a structure anyways. Either that or use a different serialization method to communicate. No one else seems to be complaining about this issue. If JSON doesn't fit your needs, use something else.
- deleted 6y ago[deleted]
- tomg 6y agoA bit off-topic but I received an email from a government agency today that pretty printed my ZIP code as "12,345", I'm assuming because they store ZIP as a number. Made me wonder what would happen if I used a full 9 digit ZIP code with a minus sign.
- adolph 6y agoReminds be of a broadly used industry specific database that packs multi-line addresses in a delimited string with an initial integer which indicates the number of lines. Some addresses were written to the database without the initial integer and were addresses in a city with East/West streets with number names. Addresses like 1425 East 34th St commonly written as 1425 E34 were casted as exponents, so an address with 1.425E37 lines, which was a problem for the ETL-downstream database that attempted to make that many rows for address lines. It caused much confusion and delay for the downstream DBAs.
- vageli 6y agoMany of the numbers we use day to day are more like strings than actual integers, though. What sense does it make to divide by a zip code, or two add two zip codes together for instance?
- Alex3917 6y agoThis. Just because something contains numbers doesn't mean that it's numeric. Times aren't numbers because 6pm * 7am doesn't yield a meaningful result. Same thing with serial numbers, VIN numbers, building floor numbers, phone numbers, etc. All of those should always be strings, because performing "math" on them wouldn't yield meaningful results.
- MaxDPS 6y agoI work in ecommerce and deal with this issue a TON. I see it in things like GTIN/UPC or tracking numbers.
- chrisandchris 6y agoWhile I basically agree, there‘s a difference between „always send numbers as string“ and „send something that looks like a number but is actually a string as a string“. Why should i send a dimension as a string? How am I going to calculate the volume from 3 strings?
- Alex3917 6y ago> Why should i send a dimension as a string? You shouldn't because a dimension is a number. Something 4 feet long is twice as long as something 2 feet long.
- chrisandchris 6y agoMany != All So prices are numbers (if supplied in cents, the smallest unit). There is length/depth/height/weight/... A lot of things are actual numbers. Why supply them as string? I agree partially with you but think ZIP are a very bad example because a zip itself may also contain letters.