- From: Kari Hurtta <hurtta-ietf@elmme-mailer.org>
- Date: Wed, 29 Jan 2020 20:17:41 +0200 (EET)
- To: HTTP Working Group <ietf-http-wg@w3.org>
- CC: Kari Hurtta <hurtta-ietf@elmme-mailer.org>, Mark Nottingham <mnot@mnot.net>, Poul-Henning Kamp <phk@varnish-cache.org>
4.1.5. Serializing a Decimal https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-15#section-4.1.5 | Given a decimal_number as input_decimal, return an ASCII string | suitable for use in a HTTP header value. | | 1. Let output be an empty string. | | 2. If input_decimal is less than (but not equal to) 0, append "-" to | output. | | 3. Append input_decimal's integer component represented in base 10 | (using only decimal digits) to output; if it is zero, append "0". | | 4. If the number of characters appended in the previous step is | greater than 12, fail serialisation. | | 5. Append "." to output. | | 6. If input_decimal's fractional component is zero, append "0" to | output. | | 7. Else if input_decimal's fractional component has up to three | digits, append them represented in base 10 (using only decimal | digits) to output. | | 8. Otherwise, append the first three digits of input_decimal's | fractional component (represented in base 10, using only decimal | digits) to output, rounding the final digit to the nearest value, | or to the even value if it is equidistant. | | 9. Return output. I'm not sure how this works. Let's input_decimal to be 123.9998 After step 3 output is "123" After step 5 output is "123." On step 8 the first three digits of input_decimal's fractional component are "999". The final digit is "9". There is no possiblity to round up that digit. So final output is "123.999". Is that orrect ? That is effectively truncation. If 123.9998 is rounded to 3 fractional decimals, value is 124.000, but that serialization can not produce it. / Kari Hurtta
Received on Wednesday, 29 January 2020 18:17:55 UTC