CrimsonZ Posted April 24, 2007 Share Posted April 24, 2007 How do get the $disc_total and round($TotalCost/12, 2) to work with printf? $disc_total = ", minus your $". $disc_rate . " discount,"; $TotalCost = ($widget_rate - $disc_rate) * 1.06; printf("<p>You requested " . $_GET[quantity] . " widgets(s) at $%.2f each.</p>",$widget_cost); printf("<p>Your total with tax" . $disc_total . " comes to $%.2f.</p> ",$TotalCost); print "You may purchase the widget(s) in 12 monthly installments of $" .round($TotalCost/12, 2) . " each."; Link to comment https://forums.phpfreaks.com/topic/48398-printf-function/ Share on other sites More sharing options...
benjaminbeazy Posted April 24, 2007 Share Posted April 24, 2007 is it not working right now? are you getting errors? Link to comment https://forums.phpfreaks.com/topic/48398-printf-function/#findComment-236676 Share on other sites More sharing options...
CrimsonZ Posted April 24, 2007 Author Share Posted April 24, 2007 is it not working right now? are you getting errors? No errors, they work fine, just that I need those 2 strings to be converted. Link to comment https://forums.phpfreaks.com/topic/48398-printf-function/#findComment-236678 Share on other sites More sharing options...
benjaminbeazy Posted April 24, 2007 Share Posted April 24, 2007 does this help any? <? if(isset($_GET['quantity'])){ $quantity = $_GET['quantity']; }else{ $quantity = 1; } $widget_rate = 20; $disc_rate = 11; $widget_cost = 10; $disc_total = ", minus your $". $disc_rate . " discount,"; $TotalCost = (($widget_rate * $quantity) * 1.06) - $disc_rate; printf("<p>You requested " . $quantity . " widgets(s) at $%.2f each.</p>",$widget_cost); printf("<p>Your total with tax" . $disc_total . " comes to $%.2f.</p> ",$TotalCost); printf("<p>You may purchase the widget(s) in 12 monthly installments of $%.2f each.", round($TotalCost/12, 2)); ?> Link to comment https://forums.phpfreaks.com/topic/48398-printf-function/#findComment-236685 Share on other sites More sharing options...
CrimsonZ Posted April 24, 2007 Author Share Posted April 24, 2007 Alright, I got the $TotalCost working but not the $disc_total. Tricky thing is, the discount is not always applied. So I would like the code to look like this: printf("<p>Your total with tax $%.2f comes to $%.2f.</p> ",$disc_total,$TotalCost); but when I do that it doesn't come out right since: $disc_total = ", minus your $". $disc_rate . " discount,"; any ideas? Link to comment https://forums.phpfreaks.com/topic/48398-printf-function/#findComment-236699 Share on other sites More sharing options...
Barand Posted April 24, 2007 Share Posted April 24, 2007 That's because $disc_total is a string, not a numeric value, having a numeric value of zero. try <?php $disc_total = sprintf(", minus your $%0.2f discount,", $disc_rate); printf("<p>Your total with tax %s comes to $%.2f.</p> ",$disc_total,$TotalCost); ?> Link to comment https://forums.phpfreaks.com/topic/48398-printf-function/#findComment-236736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.