dwest Posted March 20, 2008 Share Posted March 20, 2008 Hi, I have a piece of data supplied as a dollar amount: Example: $1.95 However, if the dollar amount happens to end in zero, then is is supplied without the zero. Example: $1.9 So, I need to test for the second digit after the decimal and if it isn't there, add a zero. How can I do that? Maybe regexp is applicable here?? Any help would be greatly appreciated. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/97021-string-manipulation-help-needed/ Share on other sites More sharing options...
pocobueno1388 Posted March 20, 2008 Share Posted March 20, 2008 You just need the number_format() function. <?php $amount = 1.9; $amount = number_format($amount, 2); echo "$$amount"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/97021-string-manipulation-help-needed/#findComment-496477 Share on other sites More sharing options...
dwest Posted March 20, 2008 Author Share Posted March 20, 2008 Hah! That was easy Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/97021-string-manipulation-help-needed/#findComment-496481 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.