"Mastering PHP Number Format: No Commas, No Problem!"

Sandra Jun 29, 2026

Mastering PHP Number Formatting: A Comma-less Approach

331 reactions ยท 68 shares | ๐ŸŸฉ Alt โ†’ H โ†’ B โ†’ A โ€“ Apply All Borders ๐ŸŸฉ Alt โ†’ H โ†’ B โ†’ N โ€“ No Borders ๐ŸŸฉ Alt โ†’ H โ†’ B โ†’ T โ€“ Top Border ๐ŸŸฉ Alt โ†’ H โ†’ B โ†’ O โ€“ Outside Border ๐ŸŸฉ Alt โ†’ H โ†’ H โ€“ Fill Color Menu ๐ŸŸฉ Alt โ†’ H โ†’ H โ†’ N | Harkesh Kumar
331 reactions ยท 68 shares | ๐ŸŸฉ Alt โ†’ H โ†’ B โ†’ A โ€“ Apply All Borders ๐ŸŸฉ Alt โ†’ H โ†’ B โ†’ N โ€“ No Borders ๐ŸŸฉ Alt โ†’ H โ†’ B โ†’ T โ€“ Top Border ๐ŸŸฉ Alt โ†’ H โ†’ B โ†’ O โ€“ Outside Border ๐ŸŸฉ Alt โ†’ H โ†’ H โ€“ Fill Color Menu ๐ŸŸฉ Alt โ†’ H โ†’ H โ†’ N | Harkesh Kumar

When working with PHP, you might find yourself in a situation where you need to format numbers without commas as thousand separators. By default, PHP's number_format function uses commas for this purpose, but what if you want to use something else, or none at all? Let's dive into how you can achieve this.

a computer screen showing the number format for a web page, and an email address
a computer screen showing the number format for a web page, and an email address

Understanding the Default Behavior

Before we explore how to remove commas, let's understand how PHP formats numbers by default. The number_format function takes four arguments: the number to format, the number of decimal places, the decimal point separator, and the thousands separator. By default, it uses a comma as the thousands separator:

Format Specifiers
Format Specifiers

echo number_format(1000000, 2); // Outputs: 1,000,000.00

Removing Commas: The Easy Way

The easiest way to remove commas is to simply not provide a thousands separator. When you omit this argument, PHP uses the platform's default separator, which is often a space or nothing at all:

MERGE SORT
MERGE SORT

echo number_format(1000000, 2, '.', ''); // Outputs: 1000000.00

Removing Commas: The Flexible Way

If you want more control over the formatting, you can use the sprintf function along with the %f format specifier. This allows you to specify the number of decimal places and the thousands separator:

echo sprintf('%f', 1000000); // Outputs: 1000000.00

Formatting Large Numbers

an image of a program with numbers and words on the back ground, which reads c + + program to display prime numbers when larger number is entered first
an image of a program with numbers and words on the back ground, which reads c + + program to display prime numbers when larger number is entered first

When dealing with very large numbers, you might want to use scientific notation. PHP provides the number_format function's SCIENTIFIC constant for this purpose:

echo number_format(123456789123456789, 2, '.', ' '); // Outputs: 1.23E+18

Formatting Currencies

When formatting currency, you typically want to include a currency symbol and two decimal places. You can achieve this with number_format and sprintf:

the numbers are displayed in blue and black on this white background, as well as an arrow
the numbers are displayed in blue and black on this white background, as well as an arrow
  • number_format:
    echo number_format(1234.56, 2, '.', ' ') . ' USD';
  • sprintf:
    echo sprintf('%.2f', 1234.56) . ' USD';

Comparing Formatting Functions

an image of some type of programming program
an image of some type of programming program
an image of a computer screen with some text in the bottom right corner and numbers on it
an image of a computer screen with some text in the bottom right corner and numbers on it
a table with numbers and symbols for each type of computer program, which is the same number
a table with numbers and symbols for each type of computer program, which is the same number
an iphone screen showing the private number on it
an iphone screen showing the private number on it
a poster with numbers and question marks on the front page, which includes symbols for each element
a poster with numbers and question marks on the front page, which includes symbols for each element
Insert Commas Into Text (Formatting Numbers in a String)
Insert Commas Into Text (Formatting Numbers in a String)
Boston Excel Consulting
Boston Excel Consulting
Java - Add two binary numbers
Java - Add two binary numbers
an image of a computer screen with many lines on it and the text in white
an image of a computer screen with many lines on it and the text in white
a screenshot of an app with numbers and symbols on the screen, which is also called what's the output of the code sinipeet?
a screenshot of an app with numbers and symbols on the screen, which is also called what's the output of the code sinipeet?
Binary numbers stock image. Image of rows, digital, computer - 14439495
Binary numbers stock image. Image of rows, digital, computer - 14439495
an advertisement with the date in english and numbers on it, which is written in black ink
an advertisement with the date in english and numbers on it, which is written in black ink
How to Convert Numbers to Binary
How to Convert Numbers to Binary
a black background with white numbers on it and the words, training features label ii
a black background with white numbers on it and the words, training features label ii
a piece of paper with writing on it that says, 445 928 80
a piece of paper with writing on it that says, 445 928 80
the numbers are shown in black and white for each type of number that is on display
the numbers are shown in black and white for each type of number that is on display
Format Numbers to Thousands and Millions in Excel
Format Numbers to Thousands and Millions in Excel
a black screen with text that says, day 9 check positive or negative number in python
a black screen with text that says, day 9 check positive or negative number in python
Give your text
Give your text
an info sheet with the words common network protools and their port numbers
an info sheet with the words common network protools and their port numbers

Here's a comparison of the different methods we've discussed, using the number 1,234,567.89:

Function Output
number_format 1,234,567.89
number_format with no thousands separator 1234567.89
sprintf 1234567.89
number_format with SCIENTIFIC constant 1.234568E+6