Navajo Posted February 27, 2009 Share Posted February 27, 2009 $fifthAmount = ($secondAmount + $thirdAmount); echo "$fifthAmount"; This prints to the screen: 1020 but I want: 000000000001020 So its 15 numbers in length. How do I append 0's to the front of a number? Link to comment https://forums.phpfreaks.com/topic/147132-append-0s-onto-the-start-of-a-number-variable/ Share on other sites More sharing options...
thebadbad Posted February 27, 2009 Share Posted February 27, 2009 You can use str_pad(): <?php $fifthAmount = ($secondAmount + $thirdAmount); echo str_pad($fifthAmount, 15, '0', STR_PAD_LEFT); ?> Link to comment https://forums.phpfreaks.com/topic/147132-append-0s-onto-the-start-of-a-number-variable/#findComment-772419 Share on other sites More sharing options...
Navajo Posted February 27, 2009 Author Share Posted February 27, 2009 Cheers, that's done it. I'm only very very new to php, where would a novice like me look for something like that bit of code? Link to comment https://forums.phpfreaks.com/topic/147132-append-0s-onto-the-start-of-a-number-variable/#findComment-772429 Share on other sites More sharing options...
thebadbad Posted February 28, 2009 Share Posted February 28, 2009 You can start with Google, if you don't know the name of the function you're about to use, and then look the function up in the manual (use the search function) for directions and examples. Link to comment https://forums.phpfreaks.com/topic/147132-append-0s-onto-the-start-of-a-number-variable/#findComment-773183 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.