Question : PHP String Help to Determine Output and Layout of a Value

We have to manipulate the output of a numerical value we query from a database.  Assume this value is a number, and can be stored as such:  25, 12.5, 34.25, 100, 250.50, 7.5, 20.00, 8.5, etc.  We are not able to control the way this value is stored.  These values represent the price of something.  

What we need is to display this as a number with different formatting. based on the length of the value and whether it has cents (something after a period.)  Again, as you see above, we have to work with the available value, and sometimes what would be outputted as $12.50 is stored as either 12.5 or 12.50.  We hard code the dollar sign.  We need to either display this as 60px font or 46px font.  

If there is no period (decimal point), we want it in 60 px font with no cents showing.  If there is a decimal, or if the length is greater than 3 characters (not counting the dollar sign which we hard code), we want it in 46 px font, with cents showing if there are cents, or no cents if there is no decimal point.    I know about number_format but do not know how to determine the length of  the string to see if there is a decimal point to create a conditional.  

Please feel free to manipulate any code below.  These are only examples so you can see how we plan to echo out the result.

Examples (assume our value is in the variable of $amount):

$amount = $row["amount"];

If our value is 25.50.  We could code this as:
<span style=" font:bold 46px arial; text-align:center; color:#FFF;"> $<? echo $amount; ?> </span>

Output of this would be $25.50 in 46 point font.


If our value is 10.  We could code this as:
<span style=" font:bold 60px arial; text-align:center; color:#FFF;"> $<? echo $amount; ?> </span>

Output of this would be $10 in 60 point font.


If our value is 7.5.  We could code this as:
<span style=" font:bold 46px arial; text-align:center; color:#FFF;"> $<? echo $amount; ?> </span>

Output of this would be $7.50 in 46 point font.


If our value is 250.  We could code this as:
<span style=" font:bold 46px arial; text-align:center; color:#FFF;"> $<? echo $amount; ?> </span>

Output of this would be $250 in 46 point font.


If our value is 50.  We could code this as:
<span style=" font:bold 60px arial; text-align:center; color:#FFF;"> $<? echo $amount; ?> </span>

Output of this would be $50 in 60 point font.

I intend to remain available to confirm solution and award points quickly.

Answer : PHP String Help to Determine Output and Layout of a Value

Anyways
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
<?
$amount = $row["amount"];
$fsize="60";
if (intval($amount)==floatval($amount))
{
  $s_amount=strval($amount);
}
else
{
  $s_amount=money_format('%.2n', $amount);
}
if (strlen($s_amount)>3) $fsize="46";
?>
<span style=" font:bold <? echo $fsize; ?>px arial; text-align:center; color:#FFF;"> $<? echo $s_amount; ?> </span>
Random Solutions  
 
programming4us programming4us