WorkMaze / JUST.net

JUST - JSON Under Simple Transformation (XSLT equivalent for JSON).
MIT License
173 stars 54 forks source link

Incorrect transformation doubles #51

Open dmelli opened 5 years ago

dmelli commented 5 years ago

Hi, first thank for great library.

Second, i find one issue when transforms float/doubles. Actually function GetValue transform json to object float and sometimes has wrong.

How reproduce: Example { "records":[ { "id":"a83D000sdfhIAA", "name":"700024", "value_1":416889.0, "value_2":1557597.06, "value_3":1557597.06, "value_4":1557597.06, "value_5":17250.11, "value_6":30.0 } ] }

Transformer { "result":{ "#loop($.records)":{ "trans_id":"#currentvalueatpath($.id)", "trans_name":"#currentvalueatpath($.name)", "trans_value_1":"#currentvalueatpath($.value_1)", "trans_value_2":"#currentvalueatpath($.value_2)", "trans_value_3":"#currentvalueatpath($.value_3)", "trans_value_4":"#currentvalueatpath($.value_4)", "trans_value_5":"#currentvalueatpath($.value_5)", "trans_value_6":"#currentvalueatpath($.value_6)" } } }

Result

{ "result":[ { "trans_id":"a83D000sdfhIAA", "trans_name":"700024", "trans_value_1":416889.0, "trans_value_2":1557597.0, "trans_value_3":1557597.0, "trans_value_4":1557597.0, "trans_value_5":17250.11, "trans_value_6":30.0 } ] }

I test change de returned value to double when the type is JTokenType.Float and work. Captures: screen shot 2019-02-14 at 4 19 48 pm

Other persons comment the same issue in the page https://www.codeproject.com/Articles/1187172/JUST-JSON-Under-Simple-Transformation?fid=1921479&df=90&mpp=25&prof=True&sort=Position&view=Normal&spc=Relaxed&fr=1#_comments. screen shot 2019-02-14 at 4 24 08 pm. With this change work too.

Thanks.

Courela commented 5 years ago

Computers have some problems when dealing with floating-point numbers: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

I suggest you do a pull request with that fix.