fazzfarrell Posted May 29, 2007 Share Posted May 29, 2007 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 https://forums.phpfreaks.com/topic/53396-solved-number-format/ Share on other sites More sharing options...
ToonMariner Posted May 29, 2007 Share Posted May 29, 2007 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 https://forums.phpfreaks.com/topic/53396-solved-number-format/#findComment-263837 Share on other sites More sharing options...
hitman6003 Posted May 29, 2007 Share Posted May 29, 2007 echo number_format ( ($number1 * (1 - $number2)) , 2); Link to comment https://forums.phpfreaks.com/topic/53396-solved-number-format/#findComment-263839 Share on other sites More sharing options...
fazzfarrell Posted May 29, 2007 Author Share Posted May 29, 2007 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 https://forums.phpfreaks.com/topic/53396-solved-number-format/#findComment-263873 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.