Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add inCents parameter to Number::currency helper #54163

Open
wants to merge 8 commits into
base: 11.x
Choose a base branch
from

Conversation

rtrudel
Copy link

@rtrudel rtrudel commented Jan 11, 2025

This pull request adds an inCents parameter to the Number::currency method, allowing us to specify whether the $number parameter is in cents. This makes it easier to format currency values without having to convert them beforehand.

As Stripe and many other payment gateways use cents-based amounts for prices, this addition simplifies the display of prices in applications.

Before:

// With a price of 1500 cents from Stripe
$price = $stripePrice / 100;
Number::currency($price); // outputs "$15.00"

After:

// With a price of 1500 cents from Stripe
Number::currency($stripePrice, inCents: true); // outputs "$15.00"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant