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] Implement formatting of fractions #54087

Closed
wants to merge 4 commits into from

Conversation

shaedrich
Copy link
Contributor

@shaedrich shaedrich commented Jan 5, 2025

Follow-up to #48845

Features

  • proper/improper fractions: When the numerator and the denominator are both positive, the fraction is called proper if the numerator is less than the denominator, and improper otherwise (e.g. 1 3/4 is "proper" while 7/4 is the same decimal in "improper" notation)
  • approximation: Not all decimals can be mapped 1:1 to fractions and vice versa. Especially, repeating decimals can sometimes be written as a fraction but not as a decimal without using additional notation (e.g. 1/3 can be approximated to 0.33, but the actual decimal would be 0.33… or 0. ̅3)
  • stylization: We, especially when writing digitally, often resort to a simplified notation for fractions (e.g. 3/4). Actually, these would have to be written with unicode characters. This notation has to options: Just marking the numerator and denominator as part of a fraction with a unicode slash and leave the rendering to the output or display the three parts manually as subscript and superscript.

Examples (see tests)

Input Limes improper approximation stylization glue Output
0.06 default default default default default null
0.75 default default default default default 3/4
1.75 default default default default default 1 3/4
1.75 default true default default default 7/4
2.33 default default default default default 2 1/3
2.33 default default default default default 2 1/3
2.33 default default false default default null
2.58 default default default default default 2 4/7
2.58 5 default default default default 2 3/5
1.97 default default default default default 2
1.75 default default default default default 1 3/4
1.75 default default default false default 1 3/4
1.75 default default default auto default 1 3⁄4
1.75 default default default manual default 1 ³⁄₄
1.75 default default default manual '' 1³⁄₄

@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

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.

2 participants