Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ ChangeLog
2.1.1 (????-??-??)
------------------

* Decimals that round to a whole number, such as `1.0001`, now serialize as
`1.0` instead of `1.`, which is invalid and was rejected by the parser.
(@gyanu2507)
* Fix: serialization of displaystring that encodes to byte values under 0xf,
they were missing the 0 padding of %0?.

Expand Down
3 changes: 2 additions & 1 deletion src/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export function serializeDecimal(input: number): string {
if (signifantDigits > 12) {
throw new SerializeError('Fractional numbers are not allowed to have more than 12 significant digits before the decimal point');
}
return out;
// A decimal must have at least one fractional digit.
return out.endsWith('.') ? out + '0' : out;
}

export function serializeString(input: string): string {
Expand Down
10 changes: 10 additions & 0 deletions test/serializer-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ describe('serializer shorthands', () => {

describe('serializeItem', () => {

it('should keep a fractional digit when a decimal rounds to a whole number', () => {

for (const [input, expected] of [[1.0001, '1.0'], [9.9999, '10.0'], [-0.0001, '-0.0']]) {
const str = serializeItem(input);
assert.equal(str, expected);
assert.deepEqual(parseItem(str), [Number(expected), new Map()]);
}

});

it('should error when passing a type that\'s not recognized', () => {

let caught = false;
Expand Down
Loading