Skip to content

Commit

Permalink
fix(entity): fix bigdecimal to entity converter (#934)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedragon authored Aug 27, 2024
1 parent e5d2b58 commit 610dc33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/sdk/src/store/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ describe('RichStruct converter tests', () => {
})

it('bigDecimal converter', () => {
testConverter(new BigDecimal('-1e100'), BigDecimalConverter)
testConverter(new BigDecimal('-0.006266950425962837'), BigDecimalConverter)
testConverter(new BigDecimal('1.006266950425962837'), BigDecimalConverter)
testConverter(
new BigDecimal('123456789012345678901234567890123456789012345678901234567890.123'),
BigDecimalConverter
Expand Down
8 changes: 6 additions & 2 deletions packages/sdk/src/store/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,16 @@ export const BigDecimalConverter: ValueConverter<BigDecimal | undefined> = {
nullValue: RichValue_NullValue.NULL_VALUE
}
}
const s = (value.c || []).join('')
const s = (value.c || [])
.map((v, idx) => {
return idx == 0 ? v.toString() : v.toString().padStart(14, '0')
})
.join('')
const exp = -(s.length - (value.e ?? 0) - 1)

return {
bigdecimalValue: {
value: toBigInteger(BigInt(s)),
value: toBigInteger(BigInt(s) * BigInt(value.s ?? 1)),
exp: exp
}
}
Expand Down

0 comments on commit 610dc33

Please sign in to comment.