diff --git a/src/value/convert/convert.ts b/src/value/convert/convert.ts index 5342320ed..cddb0cf22 100644 --- a/src/value/convert/convert.ts +++ b/src/value/convert/convert.ts @@ -119,7 +119,8 @@ function TryConvertBoolean(value: unknown) { return IsValueTrue(value) ? true : IsValueFalse(value) ? false : value } function TryConvertBigInt(value: unknown) { - return IsStringNumeric(value) ? BigInt(parseInt(value)) : IsNumber(value) ? BigInt(value | 0) : IsValueFalse(value) ? BigInt(0) : IsValueTrue(value) ? BigInt(1) : value + const truncateInteger = (value: string) => value.split('.')[0]; + return IsStringNumeric(value) ? BigInt(truncateInteger(value)) : IsNumber(value) ? BigInt(value | 0) : IsValueFalse(value) ? BigInt(0) : IsValueTrue(value) ? BigInt(1) : value } function TryConvertString(value: unknown) { return IsValueToString(value) ? value.toString() : IsSymbol(value) && value.description !== undefined ? value.description.toString() : value diff --git a/test/runtime/value/convert/bigint.ts b/test/runtime/value/convert/bigint.ts index c5057ab00..350e7a1f4 100644 --- a/test/runtime/value/convert/bigint.ts +++ b/test/runtime/value/convert/bigint.ts @@ -23,6 +23,26 @@ describe('value/convert/BigInt', () => { const R = Value.Convert(T, 'false') Assert.IsEqual(R, BigInt(0)) }) + it('Should convert bigint from string 5', () => { + const T = Type.BigInt() + const R = Value.Convert(T, '12345678901234567890') + Assert.IsEqual(R, BigInt("12345678901234567890")) + }) + it('Should convert bigint from string 6', () => { + const T = Type.BigInt() + const R = Value.Convert(T, '-12345678901234567890') + Assert.IsEqual(R, BigInt("-12345678901234567890")) + }) + it('Should convert bigint from string 7', () => { + const T = Type.BigInt() + const R = Value.Convert(T, '12345678901234567890.123') + Assert.IsEqual(R, BigInt("12345678901234567890")) + }) + it('Should convert bigint from string 8', () => { + const T = Type.BigInt() + const R = Value.Convert(T, '-12345678901234567890.123') + Assert.IsEqual(R, BigInt("-12345678901234567890")) + }) it('Should convert bitint from number 1', () => { const T = Type.BigInt() const R = Value.Convert(T, 1)