Jump to content

[SOLVED] number format


fazzfarrell

Recommended Posts

I am trying to format a number I had some help last week but I still can't get the the thing to work

 

<?php echo $row_rsProd['P_Retail_Price']; ?></strong></td>
                <td width="22%"><span class="style1">You Pay £<?php
		 //Rob Farrell and Leyon Nevett: add up design cost x hrs
$english_format_number = number_format($number);
        $number1 = $row_rsProd['P_Retail_Price'];
if (isset($_SESSION['MM_Username']))
{
	$number2 = $row_rsUser['Percent'];
}else{
	$number2 = 1;
}
             echo number_format ($number1 / $number2 * 100, 2);
?>

 

 

I have a price 52.61 but it displays as 5,261.00

 

It is done like this as when a user is logged in it take a percentage such as 17.5% from $row_rsUser['Percent']; and calculates it, if they are not logged in they don't get a discount.

 

Can someone point me in the right direction

 

thanks

Link to comment
Share on other sites

echo number_format (($number1 / $number2) * 100, 2, '.', ',');

 

the fact it is showing 5,261.00 suggest all is working well - ist just that you number is 100 times bigger than you expect - doube check you math

 

I suspect you actually want this

 

<?php echo $row_rsProd['P_Retail_Price']; ?></strong></td>
                <td width="22%"><span class="style1">You Pay £<?php
		 //Rob Farrell and Leyon Nevett: add up design cost x hrs
$english_format_number = number_format($number);
        $number1 = $row_rsProd['P_Retail_Price'];
if (isset($_SESSION['MM_Username']))
{
	$number = $number1 * $row_rsUser['Percent'];
}else{
	$number = $number1;
}
             echo number_format ($number, 2, '.',',');
?>

 

if $row_rsUser['Percent']; is anactual percentage (like 80%) then you will have to convert that to a decimal first.

Link to comment
Share on other sites

works perfect, i made a slight change and now it works for '0' percentage or 17.5

 

<?php
		 //Rob Farrell and Leyon Nevett: add up design cost x hrs
$english_format_number = number_format($number);
        $number1 = $row_rsProd['P_Retail_Price'];
if (isset($_SESSION['MM_Username']))
{
	$number = ($number1 / $row_rsUser['Percent'] * 100);
}else{
	$number = $number1;
}
             echo number_format ($number, 2, '.',',');
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.