schibsted / jslt

JSON query and transformation language
Apache License 2.0
628 stars 119 forks source link

Weird numeric error #366

Open SilverZippo opened 3 hours ago

SilverZippo commented 3 hours ago

I am using jslt to transform dinancial messages.

I had some records which were failing unexpectedly, and upon investigation, the following input caused a problem:

{ // loads of fields "LastForwardPoints" : "0.0162" }

asking for .LastForwardPoints * 100 yields "0.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.01620.0162"

strangely, if you just declare it without loads of preceeding fields, it works fine. { "LastForwardPoints" : "0.0162" }

also if you ask for number(.LastForwardPoints) it also works as expected.

catull commented 3 hours ago

The behaviour you describe is actually intended.

You are merely asking to repeat the string "0.0162" one hundred times.

What you may intend on doing is to multiply the numeric value of that string, such as:

{
  "value": 100 * number(.LastForwardPoints)
}

That yields:

{
  "value" : 1.6199999999999999
}

Good luck.