Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP - formatting number to 6 places

Featured Replies

Evening all!

 

My question is quite a simple one but I'm not sure how to go about it. I know how to get PHP to format a number to X number of decimal places but I want to format it to 6 whole number places.

 

I.e. I want to parse a string from '123' to '000123', or '1234' to '001234'.

 

I need it to add the right number of leading zeros so perhaps a strlen is a better approach?

 

I've done the following but is there a quicker way?

 

if (strlen($tempprice) == 1) {
	$fileprice = "00000" . $tempprice;
};

if (strlen($tempprice) == 2) {
	$fileprice = "0000" . $tempprice;
};

if (strlen($tempprice) == 3) {
	$fileprice = "000" . $tempprice;
};

if (strlen($tempprice) == 4) {
	$fileprice = "00" . $tempprice;
};

if (strlen($tempprice) == 5) {
	$fileprice = "0" . $tempprice;
};

if (strlen($tempprice) == 6) {
	$fileprice = $tempprice;
};

Edited by a_ginger_webdev

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.