236

Meme transcription:

Panel 1: Bilbo Baggins ponders, “After all… why should I care about the difference between int and String?

Panel 2: Bilbo Baggins is revealed to be an API developer. He continues, “JSON is always String, anyways…”

you are viewing a single comment's thread
view the rest of the comments
[-] frezik@midwest.social 2 points 4 days ago

JSON numeric encoding is perfectly capable of precise encoding to arbitrary decimal precision. Strings are easier if you don't want to fuck around with the parser, though.

Correct, JSON can handle any precision, because it's just dumped as a string anyway, just not enclosed in the "". However, as you mentioned, as soon as it comes through the parser it'll put it into an underlying float value. In C# I create a save high precision attribute that will take the value and put it directly into a decimal. In JS I'm sure there's some way to do that, but that parser is way less extensible compared to C#. However, this also all assumes you know the client will parse it correctly, overriding the default behavior. Safest is to just send it as a string, and then create your parsers to automatically send to and from strings

this post was submitted on 30 Jun 2024
236 points (97.2% liked)

Programmer Humor

31229 readers
52 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 4 years ago
MODERATORS