I want to change a value I get from my datatbase from, for example, 4 to 4.00 or 2.5 to 2.50 because I am inserting it into a string where I want to print $4.00 or $2.50. Is there a good way to do this using php?
Thanks for any help.
Change 4 to 4.00 and 2.5 to 2.50?
Moderator: General Moderators
- SmokyBarnable
- Forum Contributor
- Posts: 105
- Joined: Wed Nov 01, 2006 5:44 pm
simple..
here $num is the value you get from database and I assumed that ,you get the values from database x, x.y format only.
Code: Select all
if(is_int($num))
{
$num_str="$".$num.".00";
}
elseif(is_float($num))
{
$num_str="$".$num."0";
}
echo $num_str;- aaronhall
- DevNet Resident
- Posts: 1040
- Joined: Tue Aug 13, 2002 5:10 pm
- Location: Back in Phoenix, missing the microbrews
- Contact:
MySQL will help you out after you insert if the column type is set to
Where the first number is the length of the numbers to the left of the decimal, and the second, the length of the numbers to the right of the decimal.
Code: Select all
DECIMAL(10,2)