freddyw Posted August 2, 2009 Share Posted August 2, 2009 Ive read abiut the money_format() but i cant seem to make it work. here is my code <?php $price = $price * 1.02; if ( $result != 0 ) { echo "You are paying buy credit card. Your ticket has a transaction fee of 2.5%. Your new ticket price is $$price your card has been charged and your ticket will be dispatched shortly. Please make a note of the order id which is $id. Thankyou and enjoy the match"; } else { echo "Failed to buy"; } ?> Its displaying the price as $20.4 which in maths is correct but in money terms looks wrong. If i changed the code to <? Your new ticket price is $$price0 ?> it would work but only if the new price rounded to a 10. if it the price was 20.41 it would display 20.410 which again looks wrong. is there a way of letting the php know it is money and needs to display 20.40 thanks in advnace Quote Link to comment https://forums.phpfreaks.com/topic/168527-solved-50-instead-of-5/ Share on other sites More sharing options...
smerny Posted August 2, 2009 Share Posted August 2, 2009 try number_format($price, 2, '.', ',') Quote Link to comment https://forums.phpfreaks.com/topic/168527-solved-50-instead-of-5/#findComment-889001 Share on other sites More sharing options...
freddyw Posted August 2, 2009 Author Share Posted August 2, 2009 thanks i placed that code after &price = $price * 1.02; and im still geting the same result 20.4 not 20.40 any idea why? Quote Link to comment https://forums.phpfreaks.com/topic/168527-solved-50-instead-of-5/#findComment-889017 Share on other sites More sharing options...
smerny Posted August 2, 2009 Share Posted August 2, 2009 did you set it to equal $price? like: $price = number_format($price,2,'.',','); ? Quote Link to comment https://forums.phpfreaks.com/topic/168527-solved-50-instead-of-5/#findComment-889020 Share on other sites More sharing options...
Philip Posted August 2, 2009 Share Posted August 2, 2009 // replace: $price = $price * 1.02; // with: $price = sprintf('%.2f',$price * 1.02); Quote Link to comment https://forums.phpfreaks.com/topic/168527-solved-50-instead-of-5/#findComment-889023 Share on other sites More sharing options...
freddyw Posted August 2, 2009 Author Share Posted August 2, 2009 thanks smerny got it working thanks for the input phillip, that would have worked too Quote Link to comment https://forums.phpfreaks.com/topic/168527-solved-50-instead-of-5/#findComment-889028 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.