Login

Snippets by joelegner

Snippet List

FloatField with safe expression parsing

This FloatField replacement allows users to enter math expressions, such as: 4/5 + sqrt(32) And will evaluate them safely when the field's clean() function is called. In the example above, it will evaluate to a float value of about 6.457. Reference: [http://lybniz2.sourceforge.net/safeeval.html](http://lybniz2.sourceforge.net/safeeval.html) The available functions are listed herein. Note that the from __future__ import division causes integer division expressions to be evaluated as floats. For example "1/2" evaluates as 0.5 when it would otherwise have evaluated to 0 (assuming Python 2.X).

  • fields
  • forms
  • parser
  • math
  • eval
  • parsing
  • floatfield
Read More

Significant digits filter

Formats float values with specified number of significant digits (defaults to 3). Usage: `{{value|sigdig}} # with 3 significant digits by default` `{{value|sigdig:digits}}` Examples: `{{0.001432143|sigdig}}` renders as `0.00143` `{{874321.4327184|sigdig}}` renders as `874000` `{{874321.4327184|sigdig:5}}` renders as `874320` Useful for scientific or engineering presentation.

  • filter
  • filters
  • math
  • engineering
Read More

joelegner has posted 2 snippets.