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

NumberFormatter no longer accepts floats #68

Closed
Propaganistas opened this issue Jun 6, 2018 · 2 comments
Closed

NumberFormatter no longer accepts floats #68

Propaganistas opened this issue Jun 6, 2018 · 2 comments

Comments

@Propaganistas
Copy link
Contributor

Propaganistas commented Jun 6, 2018

I've noticed that NumberFormatter underwent some changes from 0.* tot 1.*. More specifically the percent style got some breaking changes. I'm just curious if the following ones are intended.

// version 0.*
$formatter->format(75, ['style' => 'percent']); // 75%

// version 1.*
$formatter->format(75, ['style' => 'percent']); // 7500%
// version 0.*
$formatter->format(0.75, ['style' => 'percent']); // 0.75%

// version 1.*
$formatter->format(0.75, ['style' => 'percent']); // Exception (floats cannot be passed)
$formatter->format('0.75', ['style' => 'percent']); // 75%
@Propaganistas Propaganistas changed the title NumberFormatter percent style not accepting float NumberFormatter percent style breaking changes Jun 6, 2018
@bojanz
Copy link
Contributor

bojanz commented Jun 6, 2018

Everything except the Exception was done intentionally to sync the formatter with php's NumberFormatter (which formats percentages the same way). See #67.

The float exception is a regression caused by adding rounding, since rounding always requires a string (bcmath). But we can cast to string before then.

@Propaganistas
Copy link
Contributor Author

Ok seems legit!
I'd definitely vouch for implementing a quick string cast.

@bojanz bojanz changed the title NumberFormatter percent style breaking changes NumberFormatter no longer accepts floats Jun 21, 2018
@bojanz bojanz closed this as completed in 22156e4 Jun 21, 2018
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

No branches or pull requests

2 participants