Creating APIs in Laravel 5.5 using API resources

For those of you wondering why storing a price as integer rather than as a float/double (as I was as well), this is from StackOverflow:

“You can use what’s known as minor currency. Which is basicly storing $4.20 as 420. This is a practice that is commonly adapted when communicating with payment processing gateways or api.

The benefit is that all arithmatic operations in the database and storage happens using integers rather than decimals. Which means they take up less space and operations are faster.

As pointed out by @thilo you also avoid floating point erros that can sometimes creep in.

At the time of display, simply divide by 100"

Like what you read? Give Paul G. Smith a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.