I am w开发者_高级运维orking on a code written in haml, for converting number to currency developer has coded like following.
to_currency payment.amount
It is converting number 5 as $5.00, but this is a credit amount so I need to display it as ($5.00) instead of $5.00.
Any recommendations what should I change in to_currency?
I don't know that this is really a HAML question, since you're asking what to change in your to_currency function, which is surely held in a controller or helper file, not a HAML file. However, you can interpolate the function into any HAML file like this:
You save (#{to_currency(payment.amount)})
If to_currency were to return $5.00, the above HAML line would produce:
You save ($5.00)
Depending on your code, this might be the better method, anyway. That way, you can leave your original to_currency function alone, which may be providing results to other portions of the app which expect the results with no parentheses.
精彩评论