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! 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"; ?> 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! Link to comment https://forums.phpfreaks.com/topic/97021-string-manipulation-help-needed/#findComment-496481 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.