How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: Format Numbers in Bangladeshi / Indian Style with PHP
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > Format Numbers in Bangladeshi / Indian Style with PHP
Web Development

Format Numbers in Bangladeshi / Indian Style with PHP

how7o
By how7o
Last updated: May 22, 2026
6 Min Read
PHP Bangladeshi number format — 1,00,23,456.79 grouping
SHARE

To format a number with Bangladeshi or Indian-style commas in PHP — one group of 3 on the right, then groups of 2 — there’s no single built-in. The cleanest options are PHP’s NumberFormatter (from the intl extension, locale-aware) when available, or a small custom function when intl isn’t installed. This guide covers both, plus the gotchas around negative numbers and very large balances.

Contents
  • TL;DR
  • Preferred: NumberFormatter with the Indian locale
  • Fallback: manual function
  • How the manual grouping works
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 on PHP 8.3. Originally published 2023-02-19, rewritten and updated 2026-05-17.

TL;DR

// If the intl extension is available — preferred
$fmt = new NumberFormatter('en_IN', NumberFormatter::DECIMAL);
$fmt->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);
echo $fmt->format(10023456.789);
// 1,00,23,456.79

// Manual fallback (no intl extension required)
echo format_currency(10023456.789, 2);
// 1,00,23,456.79

Preferred: NumberFormatter with the Indian locale

If your PHP install has the intl extension loaded, NumberFormatter already knows how to group South Asian numbers. The Indian-English locale (en_IN) produces the 3-2-2 pattern correctly:

$fmt = new NumberFormatter('en_IN', NumberFormatter::DECIMAL);
$fmt->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);

echo $fmt->format(10023456.789);
// 1,00,23,456.79

echo $fmt->format(1234.5);
// 1,234.50

Check availability first if you’re not sure:

if (extension_loaded('intl')) {
    // use NumberFormatter
} else {
    // fall back to the manual function below
}
PHP Bangladeshi number format — 3-2-2 grouping, NumberFormatter and manual function compared

Fallback: manual function

When intl isn’t installed (some shared hosts), build the grouping yourself. The trick is to reverse the integer portion, take the first three characters, then split the rest into pairs:

function format_currency($num, $decimal_point = 2)
{
    if (!is_numeric($num)) {
        return '0.00';
    }

    // Format to a fixed number of decimals (string output)
    $decimal_number = number_format($num, $decimal_point, '.', '');
    $parts = explode('.', $decimal_number);

    if (count($parts) !== 2) {
        return '0.00';
    }

    $integer_part = $parts[0];
    $decimal_part = $parts[1];

    // Reverse so we can chunk from the right
    $reversed = strrev($integer_part);

    // First 3 digits (the rightmost three), then groups of 2
    $groups   = [substr($reversed, 0, 3)];
    foreach (str_split(substr($reversed, 3), 2) as $chunk) {
        $groups[] = $chunk;
    }

    // Reverse back and add the decimal portion
    return strrev($decimal_part . '.' . implode(',', $groups));
}

Use it the same way as number_format:

echo format_currency(10023456.789, 2);  // 1,00,23,456.79
echo format_currency(1234.5, 2);        // 1,234.50
echo format_currency(99);               // 99.00

How the manual grouping works

  1. Format with no separator — number_format($num, 2, '.', '') gives a clean decimal string like "10023456.79".
  2. Split on the decimal point — into "10023456" and "79".
  3. Reverse the integer part — "10023456" → "65432001". This lets us chunk from the right by chunking from the left after reversal.
  4. Take the first 3 characters — "654" (which represents "456" in the original).
  5. Split the rest into pairs of 2 — "32", "00", "1".
  6. Reassemble with commas, then reverse back — "654,32,00,1" → reversed → "1,00,23,456".
  7. Append the decimal portion back on with a dot: "1,00,23,456.79".

Frequently asked questions

What is the 3-then-2 comma pattern?

It’s the standard digit grouping in South Asian numbering (used across Bangladesh, India, Nepal, Pakistan): one group of 3 on the right, then groups of 2 thereafter. 10023456.789 becomes 1,00,23,456.789. This matches everyday currency display for taka, rupees, etc. Western 3-3-3 grouping (10,023,456.789) is what number_format() produces by default.

Why doesn’t number_format() handle this?

number_format($num, 2, '.', ',') always inserts a separator every 3 digits — it has no notion of mixed grouping. PHP’s NumberFormatter class (from intl) does support locale-aware grouping, and Indian/Bangladeshi locales produce the 3-2-2 pattern correctly. But intl isn’t installed on every shared host, so the manual function in this post is a portable fallback.

Should I use NumberFormatter instead if intl is available?

Yes — when you can. (new NumberFormatter('en_IN', NumberFormatter::DECIMAL))->format(10023456.789) returns '1,00,23,456.789' for Indian English locale, no custom code needed. For Bangladesh, use 'bn_BD' with the appropriate digits or stick with en_IN for the same grouping pattern in Latin digits. Check availability with extension_loaded('intl') at runtime; fall back to the manual function below if it’s missing.

Does this handle negative numbers correctly?

The reference function in this post doesn’t — it operates on the absolute portion before splitting. For negatives, strip the sign first, format, then re-attach: $sign = $num < 0 ? '-' : ''; return $sign . format_currency(abs($num));. Easy to add but worth knowing if your codebase has negative balances or refunds.

Is this safe for very large numbers?

Up to PHP’s float precision (~15-17 significant digits), yes. Beyond that — say, a balance in paisa stored as a 20-digit integer — convert the integer to a string first, work on the string with substr and strrev, and never let it become a float. bcmath functions help if you also need arithmetic at that scale.

Related guides

  • How to Convert a String to Float in PHP
  • How to Format a Number with Decimals in JavaScript
  • How to Add Days to a Date in PHP

References

PHP NumberFormatter: php.net/manual/en/class.numberformatter.php. PHP number_format: php.net/manual/en/function.number-format.php.

TAGGED:configurationphp

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article jQuery add required attribute to input fields — .prop() method How to Add the Required Attribute to Input Fields with jQuery
Next Article Select2 auto-focus on page load — .select2('open') How to Auto-focus a Select2 Dropdown on Page Load
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

Linux add and delete users from the terminal — adduser, passwd, sudo group, userdel
Server Management

How to Add and Delete Users on a Linux Server from the Terminal

7 Min Read
Use a JavaScript variable as an object key
Web Development

How to Use a Variable as an Object Key in JavaScript

5 Min Read
Replace jQuery .each with vanilla JavaScript loops
Web Development

How to Replace jQuery’s .each() with Vanilla JavaScript

4 Min Read
Laravel migration column types cheat sheet
Web Development

Laravel Migration Column Types — Cheat Sheet

5 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?