I have a model representing billionaires and certain statistics about them. One of the fields is ytd_change
, a float representing the amount of net worth the subject gained since the previous year, in millions of US dollars. (This metric was in the original corpus, not calculated.) Negative numbers indicate losses in net worth.
For positive dollar amounts, it's simple enough. But net worth losses come out odd:
Example:
<li>{{ billionaire.name }}: ${{ billionaire.ytd_change }}M</li>
For Larry Page and Carlos Slim respectively, this evaluates to:
- Larry Page: $4720.0M
- Carlos Slim: $-75.3M
Is there an elegant way to get the negative sign in the proper place (i.e. "-$75.3M") with the built-in filters? It doesn't seem right to handle this in the view. Should I add representational methods to the model? Or is a custom filter the best answer?