This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author anders.rundgren.net@gmail.com
Recipients anders.rundgren.net@gmail.com, eric.smith, ezio.melotti, mark.dickinson, pitrou, rhettinger
Date 2016-01-30.09:29:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1454146154.32.0.892507059108.issue26229@psf.upfronthosting.co.za>
In-reply-to
Content
As I said, the problem is close to fixed in 3.5.

You should not consider the JCS specification as the [sole] target but the ability to creating a normalized JSON object which has many uses including calculating a hash of such objects.

##################################################################
# Convert a Python double/float into an ES6/V8 compatible string #
##################################################################
def convert2Es6Format(value):
# Convert double/float to str using the native Python formatter
    pyDouble = str(value)
    pySign = ''
    if pyDouble.find('-') == 0:
#
#     Save sign separately, it doesn't have any role in the rest
#
        pySign = '-'
        pyDouble = pyDouble[1:]
    pyExpStr = ''
    pyExpVal = 0
    q = pyDouble.find('e')
    if q > 0:
#
# Grab the exponent and remove it from the number
#
        pyExpStr = pyDouble[q:]
        if pyExpStr[2:3] == '0':
#
# Supress leading zero on exponents
#
            pyExpStr = pyExpStr[0:2] + pyExpStr[3:]
        pyDouble = pyDouble[0:q]
        pyExpVal = int(pyExpStr[1:])
#
# Split number in pyFirst + pyDot + pyLast
#
    pyFirst = pyDouble
    pyDot = ''
    pyLast = ''
    q = pyDouble.find('.')
    if q > 0:
        pyDot = '.'
        pyFirst = pyDouble[0:q]
        pyLast = pyDouble[q + 1:]
#
# Now the string is split into: pySign + pyFirst + pyDot + pyLast + pyExpStr
#
    if pyLast == '0':
#
# Always remove trailing .0
#
        pyDot = ''
        pyLast = ''
    if pyExpVal > 0 and pyExpVal < 21:
#
# Integers are shown as is with up to 21 digits
#
        pyFirst += pyLast
        pyLast = ''
        pyDot = ''
        pyExpStr = ''
        q = pyExpVal - len(pyFirst)
        while q >= 0:
            q -= 1;
            pyFirst += '0'
    elif pyExpVal < 0 and pyExpVal > -7:
#
# Small numbers are shown as 0.etc with e-6 as lower limit
#
        pyLast = pyFirst + pyLast
        pyFirst = '0'
        pyDot = '.'
        pyExpStr = ''
        q = pyExpVal
        while q < -1:
            q += 1;
            pyLast = '0' + pyLast
#
# The resulting sub-strings are concatenated
#
    return pySign + pyFirst + pyDot + pyLast + pyExpStr
History
Date User Action Args
2016-01-30 09:29:14anders.rundgren.net@gmail.comsetrecipients: + anders.rundgren.net@gmail.com, rhettinger, mark.dickinson, pitrou, eric.smith, ezio.melotti
2016-01-30 09:29:14anders.rundgren.net@gmail.comsetmessageid: <1454146154.32.0.892507059108.issue26229@psf.upfronthosting.co.za>
2016-01-30 09:29:14anders.rundgren.net@gmail.comlinkissue26229 messages
2016-01-30 09:29:13anders.rundgren.net@gmail.comcreate