[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

format a number to fit xxxx

Hi

I want to format a number to fill a 4 digit space, but not like
0003
0100
0001


I want it to use dashes, or another character of my choice? such as
---3
-100
---1

is this possible?

Neil
0
Neil Thompson
Asked:
Neil Thompson
1 Solution
 
RoonaanCommented:
$formatted = sprintf('%-4d', $number);

or

$formatted = sprintf('%04d', $number);

-r-
0
 
snoyes_jwCommented:
http://www.php.net/strpad

Pass '-' as the third parameter, and STR_PAD_LEFT as the fourth.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now