## Re:Liz, Chris, and Michel ....

"Nick" <

XXXX@XXXXX.COM >writes:

##### Quote

Good Day All,

As embarassed as I am to be asking the question, your suggestions

were not quite there.

What I have is this - how many 30 day months exist between two

dates.

I have created a function that will deal with this and give me

back a Div_T, a structure containing a quot and remainder of dividing

two integers.

That being said, when I want to determine pay, I can say that an

employees pay will be:

Pay = (WholeMonths * Rate) + ((RemDays / 30) * Rate);

I wouldn't suggest using floating point math for prices or money

values, a subtle rounding errors will occur, and multiplication can

amplify the errors.

##### Quote

Its the RemDays/30 thats the problem. I was hoping to get

0.73333. But instead, I am getting some very small or very large

number.

What about 31-day months?

If you're getting weird results, I again ask for code to demonstrate

what you're doing that reproduces the problem.

##### Quote

When I had used ADouble in my example earlier, that was only to

store the result of (RemDays/30) * Rate;

What type is it? I would guess a "double" but you never said that.

##### Quote

So, what else can I try? BTW - thanks, but the fmod returned 22.

I'm not an accountant and don't like to pretend to be one, but I work

with prices and even today am looking into some problems in code

related to prices and floating point math. I'm almost to the point of

representing prices and money in a new unit: microdollars. This would

be a 64-bit integer, with the number multiplied by a million (well,

2^20). Then all math can be done without any rounding at all.

Perhaps, though, you might want to think about your calculations in

terms of net days (or net time) times rate, rather than arbitrarily

breaking that net amount of time into days and months, and performing

math on each piece and summing those results. (Provided that working

on one big number is not large enough to worry about overflow, as

compared to working with many smaller values.)

--

Chris (TeamB);