Standard representation for arbitrary size/precision numbers

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 1K views
Messages
5,020
Reaction score
3,265
Is there a standard way of representing numbers of arbitrary size or precision for storage in a text file, JSON message, variable etc.?

I am thinking of representing integers as decimal strings e.g. "-12345678901234567" and floats as an ordered pair (array) of strings representing decimal mantissa and exponent e.g. ["-1.2345678901234567", "17"], but if there is some existing standard I would rather follow that.
 
Physics news on Phys.org
Short answer: depends on what the text file is for.

Just for any old text file, the standard form is as decimal or scientific notation.
Usually an e is used between mantissa and exponent where x10^ is not available.

The only reasons to depart from them is if the text file must be parsed by something that cannot cope with the numbers - in which case you use the format recognized by the parser.
 
Thanks, JavaScript in particular is going to have problems with big integers or high precision numbers so I think I will invoke the "format recognised by the parser" pattern.