cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

BigInt in javascript

JU_10321794
8-Gravel

BigInt in javascript

So i was working on some big number within thingworx and got some unexpected results.

 

 

 

var BIGINT_OUT_OF_BOUNDS	= Number("-9223372036854775805");
result = BIGINT_OUT_OF_BOUNDS;

 

 

This will result in -9223372036854776000

If you read the javascript documentation this is understandable.

 

So i did:

 

 

var BIGINT_OUT_OF_BOUNDS	= BigInt("-9223372036854775805");
result = BIGINT_OUT_OF_BOUNDS;

 

 

This will result in an error: Error executing service BigInt. Message :: ReferenceError: "BigInt" is not defined. - See Script Error Log for more details.

 

Witch is understandable because thingworx uses Rhino 1.7.11. And BigInt is only implemented from Rhino version 1.7.14.

 

I must be missing something.

So my question is, how am i supposed to work with big numbers?

4 REPLIES 4

Besides replacing the Rhino library, which is not a supported, neither recommended operation from my PTC perspective, I don't see a way to use it.

Just curious, why do you need to work with BigInt?

 

 

Well,

We use SQL server to store data. Some whole numbers dont seem to fit a float(not precise enough) nor a integer(to small), but the BigInt is a perfect match.

At the edge of each number we reserve a few numbers for error statuses.

So for a bigint we use -9223372036854775805 to indicate that we received a number that is not in the bigInt range.

so in stead of an sql error(' Arithmetic overflow error') that results in no new record, we would check if the input value is between  -9,223,372,036,854,775,804 and 9,223,372,036,854,775,807.

if not we would insert -9223372036854775805

We prefer this above having a null in the database. because we can check why it was not inserted. and visualise that to the customer. as "Out of range"

Rocko
17-Peridot
(To:JU_10321794)

For this use case, why not use a string comparison, which also supports < and >?

One possible alternative is to write a Java extension to handle these types of cases.  Not sure if this is the latest docs, but it can get you started.  Your use case should be fairly simple to code up:  https://community.ptc.com/sejnu66972/attachments/sejnu66972/twxdevs/8416/1/thingworx_extension_development_user_guide.pdf

Top Tags