Standard representation for arbitrary size/precision numbers

Click For Summary
SUMMARY

The discussion centers on the standard representation of arbitrary size and precision numbers for storage in text files, JSON messages, and variables. It concludes that integers should be represented as decimal strings (e.g., "-12345678901234567") and floats as an ordered pair of strings for mantissa and exponent (e.g., ["-1.2345678901234567", "17"]). The standard forms for general text files are decimal or scientific notation, using 'e' to denote the exponent when necessary. Special considerations must be made for parsers, particularly in JavaScript, which struggles with large integers and high precision numbers.

PREREQUISITES
  • Understanding of JSON data formats
  • Familiarity with decimal and scientific notation
  • Knowledge of JavaScript number handling
  • Basic concepts of data serialization
NEXT STEPS
  • Research JSON number representation standards
  • Learn about JavaScript BigInt for handling large integers
  • Explore data serialization techniques for high precision numbers
  • Investigate alternative formats for number representation in text files
USEFUL FOR

Software developers, data engineers, and anyone involved in data serialization and number representation in programming, particularly those working with JSON and JavaScript.

pbuk
Science Advisor
Homework Helper
Gold Member
Messages
4,973
Reaction score
3,226
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.
 
Technology 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.
 

Similar threads

  • · Replies 32 ·
2
Replies
32
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
4
Views
2K
Replies
9
Views
2K
  • · Replies 21 ·
Replies
21
Views
7K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 87 ·
3
Replies
87
Views
9K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K