Jump to content

Increment values every .25 in a for loop


Go to solution Solved by eldan88,

Recommended Posts

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>
Link to comment
https://forums.phpfreaks.com/topic/286926-increment-values-every-25-in-a-for-loop/
Share on other sites

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>
  • Solution

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?

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.

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.

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.

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.