eldan88 Posted March 12, 2014 Share Posted March 12, 2014 Hey Guys. I am trying to add a tip function on a resturants online ordering page. I am having trouble incrementing the value .25 cents. Does anyone have any suggestions on how to do this. All help would be really appreciated.. below is what I have so far. <select> <?php for($tip=0.00; $tip<=11.75; $tip++){ echo "<option value=\"$tip\">"."$".$tip ."</option>"; }; ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/286926-increment-values-every-25-in-a-for-loop/ Share on other sites More sharing options...
requinix Posted March 12, 2014 Share Posted March 12, 2014 $tip++ is shorthand for $tip = $tip + 1. Quote Link to comment https://forums.phpfreaks.com/topic/286926-increment-values-every-25-in-a-for-loop/#findComment-1472377 Share on other sites More sharing options...
eldan88 Posted March 12, 2014 Author Share Posted March 12, 2014 Hey Requinix. Oh okay. I never knew that! I changed the following statement to this $tip=0.00; $tip<=11.75; $tip+=0.25 It works on the browser, but it doesn't show the zero change is .50 cents. For example it would show 2.5 not 2.50 Would you know how to change that? Here is my code again <select> <?php for($tip=0.00; $tip<=11.75; $tip+=0.25){ echo "<option value=\"$tip\">"."$".$tip ."</option>"; }; ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/286926-increment-values-every-25-in-a-for-loop/#findComment-1472378 Share on other sites More sharing options...
.josh Posted March 12, 2014 Share Posted March 12, 2014 sprintf dude seriously.. stop walking around in the dark. RTFM. It's one of the best manuals ever made, ever. Quote Link to comment https://forums.phpfreaks.com/topic/286926-increment-values-every-25-in-a-for-loop/#findComment-1472380 Share on other sites More sharing options...
Solution eldan88 Posted March 12, 2014 Author Solution Share Posted March 12, 2014 sprintf dude seriously.. stop walking around in the dark. RTFM. It's one of the best manuals ever made, ever. I always read the manual. But how do you expect me to pin point the exact PHP function for the question I asked requinix? Quote Link to comment https://forums.phpfreaks.com/topic/286926-increment-values-every-25-in-a-for-loop/#findComment-1472382 Share on other sites More sharing options...
eldan88 Posted March 12, 2014 Author Share Posted March 12, 2014 I will read more of it tonight and have a nice romantic evening with it....haha Quote Link to comment https://forums.phpfreaks.com/topic/286926-increment-values-every-25-in-a-for-loop/#findComment-1472383 Share on other sites More sharing options...
Psycho Posted March 12, 2014 Share Posted March 12, 2014 You can't honestly say you made a real effort to find the solution yourself. If you Google any number of things you would have found the answer in about 20 seconds: "php format number" "php show number as currency" "php number trailing zeros", etc. Quote Link to comment https://forums.phpfreaks.com/topic/286926-increment-values-every-25-in-a-for-loop/#findComment-1472384 Share on other sites More sharing options...
.josh Posted March 12, 2014 Share Posted March 12, 2014 googling "php format string" gives that function as first result. googling "php format number" gives another alternative number_format. It's literally as easy as typing in exactly what you ask here. I'm not trying to be a douche and I'm trying to give you the benefit of the doubt, but I'm starting to get the impression that you're treating us like your personal google service. Quote Link to comment https://forums.phpfreaks.com/topic/286926-increment-values-every-25-in-a-for-loop/#findComment-1472385 Share on other sites More sharing options...
eldan88 Posted March 12, 2014 Author Share Posted March 12, 2014 No not at all. That's the last thing I would ever want to do. I know you guys are helping me for free, and would never want to take advantage. I'm just really passionte about this stuff and thought you guys can help me. But you guys are right. I will try to look up these simple questions on google, then coming here and asking away. I do want to thank you guys for trying to help me. It means alot. Quote Link to comment https://forums.phpfreaks.com/topic/286926-increment-values-every-25-in-a-for-loop/#findComment-1472390 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.