Subject Re: Hourly rate Adam 2005-10-22T06:48:12Z
> Hi Alexandre:
>
> The problem is this:
> You wrote:
>
> x = 2.22 hour = 2 hour and 13 minutes
>
> HOW do You know that 2.22 = 2 h and 13 min??
>
> The others things are ALREADY solved, what I don't know is how
> to traslate 2.22 in 02:13
>
> eg: cast( as time )?
>
> Thanks
>
> Arnaldo
>

Arnaldo,

You really made it sound like you were asking a maths question rather
than anything remotely related to FB (which I why others thought you
were joking). It is strictly a maths question, the only Firebird
related part to it is perhaps how to use the floor function and how to
cast the result to an integer.

There is a UDF called IB_UDF. There are a function inside it that is
of interest. FLOOR will

Assuming X = 2.22 etc.

Hours = FLOOR(X); -- which = 2

Y = (X - FLOOR(X)); -- which = 2.22-2 = 0.22

Mins = Y * 60;

Mins may not be a whole number (there may be seconds which are also
expressed in decimals.

CREATE PROCEDURE SP_DECIMALHOURSTOHRMIN
(
DECIMALHOURS NUMERIC(18,4)
)
RETURNS
(
HOURS INTEGER
MINS INTEGER
)
AS
BEGIN
HOURS = CAST(FLOOR(:DECIMALHOURS) AS INTEGER);
MINS = CAST(60 * (:DECIMALHOURS - FLOOR(:DECIMALHOURS)) AS INTEGER);
SUSPEND; -- if you will be using select syntax
END
^

SELECT HOURS,MINS
FROM SP_DECIMALHOURSTOHRMIN(2.22);

Simple. In fact I think you do not have to even use floor at all, just
casting a float to an integer will do the same thing.