/    Sign up×
Community /Pin to ProfileBookmark

Add commas to numbers

Is there a way to add commas to numbers? Examples:

111222333 to 111,222,333
12345 to 12,345
123 unchanged

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@bokehAug 14.2006 — [code=php]$with_commas = preg_replace('/(?<=d)(?=(ddd)+$)/', ',', $number);[/code]
Copy linkTweet thisAlerts:
@pcthugAug 15.2006 — Bokeh, why not make use of the inbuilt number_format function?
[code=php]
$with_commas = number_format($number);
[/code]
Copy linkTweet thisAlerts:
@bokehAug 15.2006 — Bokeh, why not make use of the inbuilt number_format function?[/QUOTE]No reason not to do it that way but here (Spain) the notation is different meaning all four arguments would be needed.
Copy linkTweet thisAlerts:
@shane_carrauthorAug 15.2006 — number_format() works, thanks!
×

Success!

Help @shane_carr spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...