Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Standard representation for arbitrary size/precision numbers

  1. Jun 8, 2015 #1
    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.
     
  2. jcsd
  3. Jun 8, 2015 #2

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    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.
     
  4. Jun 8, 2015 #3
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Standard representation for arbitrary size/precision numbers
Loading...