[SERVER-23263] Decimal128: Scientific notation Created: 21/Mar/16  Updated: 06/Jun/16  Resolved: 31/May/16

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 3.3.8

Type: Improvement Priority: Major - P3
Reporter: Hannes Magnusson Assignee: Vincent Do
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Integrate+Tuning 14 (05/13/16), Integrate+Tuning 15 (06/03/16)
Participants:

 Description   

Apparently there is a standard for when to use scientific.

See: http://speleotrove.com/decimal/daconvs.html#reftostr

to-scientific-string – conversion to numeric string

This operation converts a number to a string, using scientific notation if an exponent is needed. The operation is not affected by the context.
 
If the number is a finite number then:
 
    The coefficient is first converted to a string in base ten using the characters 0 through 9 with no leading zeros (except if its value is zero, in which case a single 0 character is used).
    Next, the adjusted exponent is calculated; this is the exponent, plus the number of characters in the converted coefficient, less one. That is, exponent+(clength-1), where clength is the length of the coefficient in decimal digits.
    If the exponent is less than or equal to zero and the adjusted exponent is greater than or equal to -6, the number will be converted to a character form without using exponential notation. In this case, if the exponent is zero then no decimal point is added. Otherwise (the exponent will be negative), a decimal point will be inserted with the absolute value of the exponent specifying the number of characters to the right of the decimal point. ‘0’ characters are added to the left of the converted coefficient as necessary. If no character precedes the decimal point after this insertion then a conventional ‘0’ character is prefixed.
    Otherwise (that is, if the exponent is positive, or the adjusted exponent is less than -6), the number will be converted to a character form using exponential notation. In this case, if the converted coefficient has more than one digit a decimal point is inserted after the first digit. An exponent in character form is then suffixed to the converted coefficient (perhaps with inserted decimal point); this comprises the letter ‘E’ followed immediately by the adjusted exponent converted to a character form. The latter is in base ten, using the characters 0 through 9 with no leading zeros, always prefixed by a sign character (‘-’ if the calculated exponent is negative, ‘+’ otherwise). 



 Comments   
Comment by Githook User [ 31/May/16 ]

Author:

{u'username': u'vincentdo', u'name': u'Vincent Do', u'email': u'do.vincent@live.com'}

Message: SERVER-23263 - Make Decimal128 toString() conform to new spec
Branch: master
https://github.com/mongodb/mongo/commit/5b6b62d54476a5ce8631847ef0f4a2315f341cc6

Generated at Thu Feb 08 04:02:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.