Best approach to save "price" field

What is the best approach to save decimal values like price, subtotal, and total in a Laravel migration? In my app, I’m using
$table->decimal('total', 10, 2);
$table->decimal('total', 10, 2);
but since I’m using PostgreSQL, it’s not working. I’m also trying to format the values like this:
$set(
'total',
Number::format(
$subtotal,
maxPrecision: 2
)
); // The format results in something like 596,490, which isn't working for decimals.
$set(
'total',
Number::format(
$subtotal,
maxPrecision: 2
)
); // The format results in something like 596,490, which isn't working for decimals.
How can I fix this?
6 Replies
Matthew
Matthew2mo ago
Common approavh is to use int Store everything in pence\cents and format for display using money()
Shaung Bhone
Shaung BhoneOP2mo ago
So, is that okay? I saved like that
No description
Shaung Bhone
Shaung BhoneOP2mo ago
Or like that?
No description
Matthew
Matthew2mo ago
What is your column type ?
Shaung Bhone
Shaung BhoneOP2mo ago
Both are decimal used format do not use format
Want results from more Discord servers?
Add your server