Skip to content

Feature Request: Add Number Formatting for Indian Numbering System #18505

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

Closed
johnson361 opened this issue May 6, 2025 · 2 comments
Closed

Feature Request: Add Number Formatting for Indian Numbering System #18505

johnson361 opened this issue May 6, 2025 · 2 comments

Comments

@johnson361
Copy link

Description

I would like to request a feature for PHP that adds support for the Indian numbering system, which is widely used in India and other South Asian countries. In this system, large numbers are formatted differently from the Western system. The formatting includes terms like lakhs (1,00,000) and crores (1,00,00,000).

For example, the number 1234567 should be formatted as 12,34,567 (instead of 1,234,567 in the Western system).

Motivation:
This feature will be particularly useful for developers in India and neighbouring countries who need to display numbers in a format that aligns with the Indian number system. Currently, PHP only supports the Western number formatting system, and there is no built-in function for Indian number formatting.

Proposed Solution:
New Function: Introduce a function like number_format_indian($number) that will format numbers according to the Indian numbering system.

Example:
number_format_indian(1234567); // Output: 12,34,567
Customizable: Allow users to customize the separator if necessary (e.g., for different locales).

Edge Cases: Handle special cases like numbers with decimals (e.g., 1234567.89 should become 12,34,567.89).

Example in Action:

echo number_format_indian(1234567);   // Outputs: 12,34,567
echo number_format_indian(987654321); // Outputs: 98,76,54,321

Alternatives:
We could also consider enhancing the existing number_format() function by adding an option for the Indian number format.

Impact:
Backward Compatibility: This feature will be optional and won't affect existing functionality.

Localization: It would make PHP more useful for applications targeting users in India and other South Asian countries.

@devnexen
Copy link
Member

devnexen commented May 6, 2025

just a rapid glance, not sure I get your feature request, but seems number_format supports indian numeration just fine.

$fmt = numfmt_create("en_IN", NumberFormatter::DECIMAL);
var_dump(numfmt_format($fmt, 987654321));

// or

$fmt = new NumberFormatter("en_IN", NumberFormatter::DECIMAL);
var_dump($fmt->format(987654321));
string(12) "98,76,54,321"
string(12) "98,76,54,321"

@devnexen
Copy link
Member

devnexen commented May 6, 2025

Since I see you "thumbed up" it, I assume it s working out for you @johnson361. Let's close it then.

@devnexen devnexen closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants