Page 1 of 1

Formating Number?

Posted: Sat Mar 13, 2010 8:27 am
by nitediver
Anyone know how to formatting number this situation...

Code: Select all

 
<?
...
    <td width=\"25%\">$result[price]</td>
...
?>
 
all I know is this, but doesnt work since im using "$result[price]"

Code: Select all

$number = (",",".",number_format($number));

Re: Formating Number?

Posted: Sat Mar 13, 2010 10:45 am
by McInfo
You can concatenate the HTML strings and the string returned by the function.

Code: Select all

<?php echo '<td width="25%">' . number_format($result['price'], 2, '.', ',') . '</td>'; ?>
You can output the HTML directly (drop out of PHP mode) and enter PHP mode to echo the result of the function.

Code: Select all

<td width="25%"><?php echo number_format($result['price'], 2, '.', ','); ?></td>
You can store the result of the function in a variable and embed the variable in a string.

Code: Select all

<?php
$price = number_format($result['price'], 2, '.', ',');
echo "<td width=\"25%\">$price</td>";
You can pass the returned value to printf() or sprintf().

Code: Select all

<?php printf('<td width="25%%">%s</td>', number_format($result['price'], 2, '.', ',')); ?>
You can't, however, call a function from within a string.

Edit: This post was recovered from search engine cache.

Re: Formating Number?

Posted: Mon Mar 15, 2010 6:23 am
by nitediver
Anyone can help me?