title: Convert ast.Num to decimal.Decimal for precision in python
body: <p>I'm currently writing a parser to parse simple arithmetic formula: which only need (and restrict) to support +-*/ on number and variables. For example:</p>
  
  <pre><code>100.50*num*discount
  </code></pre>
  
  <p>It's basicly used to calculate price on products.</p>
  
  <p>This is written in python and i would like to just use python's own parser for simplicity. The idea is firstly parse the input into ast, then walk on the ast to restrict the ast's node type in a small subset, say: <code>ast.BinOp</code>, <code>ast.Add</code>, <code>ast.Num</code>, <code>ast.Name</code> and so on...</p>
  
  <p>Currently it works well, except that the float  point number in the ast is not precise. So i want to transform the ast's <code>ast.Num</code> node into some <code>ast.Call(func=ast.Name(id='Decimal'), ...)</code>. But the problem is: <code>ast.Num</code> only contains a <code>n</code> field that is the already parsed float point number. And it's not easy to get the original numeric literal in source code: <a href="https://stackoverflow.com/questions/16748029/how-to-get-source-corresponding-to-a-python-ast-node">How to get source corresponding to a Python AST node?</a></p>
  
  <p>Is there any suggestion?</p>