Skip to content

Instantly share code, notes, and snippets.

/example.js Secret

Created July 24, 2013 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4290ea9cf20de7efe267 to your computer and use it in GitHub Desktop.
Save anonymous/4290ea9cf20de7efe267 to your computer and use it in GitHub Desktop.
Using a custom renderer function in ExtJS4 to properly handle currency rounding
/*Uses https://github.com/MikeMcl/big.js/
to allow for arbitrary decimal precision and
get away from floating point inaccuracy
*/
{
xtype : 'numbercolumn',
header : 'Price',
dataIndex : 'line_item_price',
renderer : function( v ) {
return '$' + Big( v ).toFixed(2);
}
}
// The example number is 20.775
// Calling this renderer with v = 20.775
// returns "$20.78" as expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment