Formating Number?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nitediver
Forum Contributor
Posts: 109
Joined: Tue Feb 24, 2009 9:05 am

Formating Number?

Post 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));
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Formating Number?

Post 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.
Last edited by McInfo on Thu Jun 17, 2010 5:21 pm, edited 1 time in total.
nitediver
Forum Contributor
Posts: 109
Joined: Tue Feb 24, 2009 9:05 am

Re: Formating Number?

Post by nitediver »

Anyone can help me?
Post Reply