Reputation: 2012
It seems like how currencies are displayed has evolved over the years.
I have found Number::currency()
to be the most recent option, but doesn't account for the integer values from the database intending to be treated as /100
;
100
-> $100
where the intended output is: $1.00
What is the modern way to store, compute (add/subtract), and display currencies in Laravel? I imagine I could do the first two (store, compute) as integers, but to display would need Number::currency($val/100)
, which feels kludgy.
I have also seen solutions that make use of packages (moneyphp/money for example), but would rather keep my implementation simple, and use a native solution.
Upvotes: 1
Views: 846
Reputation: 233
Store as decimal(8,2)
Display and format with Number::currency()
Upvotes: 1