Skip navigation
Currently Being Moderated

How do I round up a total to the nearest dollar?

Jun 8, 2012 5:58 AM

I have a form that multiplies the number of items by $6.07 but I need the total to round up to the nearest dollar. I have formatted the total field to be integer and selected integer in the binding tab, which works to drop the cents out of the total but that doesn't help it round up. I suspect a script is needed to accomplish this. How do I write this script?

 

Thanks for your help.

 
Replies
  • Currently Being Moderated
    Jun 8, 2012 11:54 PM   in reply to jeanette614

    Hi,

     

    In JavaScript you can use the toFixed method of the number object to round to an whole number. So if variable total had a value of 10.5 then total.toFixed() would give you 11.

     

    One catch is that toFixed() returns a string value so it might not format exactly how you expect, so

     

    parseInt(total.toFixed())

     

    Will return a number value.

     

    Regards

     

    Bruce

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2012 3:14 PM   in reply to jeanette614

    Hi,

     

    The FormCalc equivilant is the Round function, so;

     

    Round(Table2.Row8.Eight * 6.07, 0)

     

    With the second parameter to Round being the number of decimal places, which defaults to zero so in this case you could just write;

     

    Round(Table2.Row8.Eight * 6.07)

     

    Regards

     

    Bruce

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 12, 2012 3:12 PM   in reply to jeanette614

    You will want to use the Ceil function instead, which returns the next whole number greater than the expression, so;

     

    Ceil(Table2.Row8.Eight * 6.07)

     

    Just note that this will only for positive numbers, if you have to deal with negative numbers (maybe a refund) then you will need to use the Floor function.

     

    Regards

     

    Bruce

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points