83 | | Using Decimal may cause rounding errors even before they get to Pyson, because json converts them to float. And floats can not represent all decimals accurately. For example, in python {{{str(0.24745759773026107) == '0.24745759773026108'}}}. Overall, a number string "N" in your json text will converted as {{{Decimal(str(float("N")))}}} . When in doubt, check for your number "N" that str(float(N))==N, if not you have a rounding issue. |
84 | | }}} |
| 83 | in python, the default json.loads() parses all floating point numbers to {{{float}}}. This may result in rounding errors. For example, in python {{{str(0.24745759773026107) == '0.24745759773026108'}}}. Pyson can only take these float numbers and proceed from there. |
| 84 | }}} |
| 85 | |
| 86 | {{{#!td style="background: #efe" |
| 87 | To avoid rounding errors on floating point numbers we recommend to use the parse_float option in json: {{{json.loads(yourstring, parse_float=lambda x:Decimal(x)}}}. This parses all floating point numbers as Decimal with unlimited precision. Of course the rest of your code must be able to handle this. |
| 88 | }}} |
| 89 | |
| 90 | |
| 91 | |