[eluser]digitalbloke[/eluser]
Hi all. I had a quick question about the best way to format data before outputting it to the user.
For example. Say I have an online store and I want to output the price of an item. Sometimes I might want to prefix the price with a currency symbol, and I may also want to format the number for larger numbers, i.e: £1,850.00 But other times I want to output the price as a simple number, i.e: 1850.00 (maybe in an input field within the admin area).
So, in short, where would you format the number? These are the options as I see them:
1) In the Model, but as far as I understand it, models should be just database actions.
2) Add the formatting option in the view. This could cause a problem if I wanted to allow the user to choose how they wanted to format prices / dates from a number of options, and might also cause non-continuity throughout the site.
As I see it, this leaves my third idea:
3) In a Library that corresponds to the Model. i.e the get_price() function in the library, gets the price from the model, and then if a "format" boolean is set to true returns a formatted version of the number.
Am I making this far too complicated?
Thanks in advance,
Tom.