Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Greatest Integer Function Problem

  1. Oct 25, 2006 #1
    I just need a push in the right direction for this one.
    The problem is: A phone company charges this amount for the first minute and that amount for each additional minute. If someone talks for 3.1 minutes, they are charged for 4 minutes. Make a formula, blah blah blah...
    Anyway I'm having trouble with making the equation work for both of these situations: when x is an integer, and when x is not an integer.
    I already thought about int(x-.1) but then x could be .01, and it wouldn't be correct.

    Any help is appreciated.
  2. jcsd
  3. Oct 26, 2006 #2


    User Avatar
    Science Advisor
    Homework Helper

    You're trying to make a "round up" function. Since you're allowed to use the floor ("round down") function, consider this:

    int(x)=-int(-x), x is an integer
    int(x)=1-int(-x), otherwise
  4. Oct 26, 2006 #3


    User Avatar
    Science Advisor

    All you need is a + b ceil(x-1), where a is the cost for the first minute and b is the cost of each additional minute.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Greatest Integer Function Problem