6 Replies Latest reply on Sep 7, 2009 5:46 AM by morten@mw-grafisk.dk

How to make time round up to nearest half hour ?

Greetings all

I have previously recieved excellent and highly competent help in these forums, and hope to have this issue resolved as well...

The setup is an Acroform built in Acrobat 9.1.3

This regards a situation where the user enters a 'start' and 'end' time for a given event, and the result is calculated in a decimal number - All this is working properly.

The issue is to have the time calulated to round up to the nearest half-hour, making the decimal number be either x.0 or x.5

/Morten

• 1. Re: How to make time round up to nearest half hour ?

It's not clear whether you're using regular numbers or a Date object to represent the time.

If numbers, then you can use this to achieve what you described:

if ((x!=0.5) && (x % Math.floor(x))!=0.5) {
if (Math.round(x)==Math.ceil(x))
{x = Math.ceil(x)}
else x = Math.ceil(x)-0.5;
}

I just wrote this now, maybe there's a more elegant way to do it...

• 2. Re: How to make time round up to nearest half hour ?

You are right... Perhaps I did explain too much

The problem boiled down is this :

I have a number with one decimal, which needs to be rounded up to either x.5 or x.0 depending on the following intervals :

0.0 = 0.0

0.1 -> 0.4 = 0.5

0.5 = 0.5

0.6 -> 0.9 = 0.0

...and well met, again...

/Morten

• 3. Re: How to make time round up to nearest half hour ?

You say "round up", but this rule:

0.6 -> 0.9 = 0.0

is not rounding up. It's rounding down. Or did you mean this:

0.6 -> 0.9 = 1.0

?

• 4. Re: How to make time round up to nearest half hour ?

I did

I was mostly thinking about the digit after the separator...

• 5. Re: How to make time round up to nearest half hour ?

In that case you can use the code from my first post. It does exactly that.

• 6. Re: How to make time round up to nearest half hour ?

I am now officially jumping up and down with joy... It works

It seems I made a typing error while attempting your script the first time... Just typical...

Thank you

/Morten