# Board index » cppbuilder » Liz, Chris, and Michel ....

## Liz, Chris, and Michel ....

2006-01-10 04:12:00 AM
cppbuilder37
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);
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.
When I had used ADouble in my example earlier, that was only to store the result of (RemDays/30) * Rate;
So, what else can I try? BTW - thanks, but the fmod returned 22.
Thanks,Nick

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

Hi,
Nick wrote:
##### Quote

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

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.

When I had used ADouble in my example earlier, that was only to store the result of (RemDays/30) * Rate;

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

// It seems to me that, dividing a by b (both integer),
// the number you want is :
float x=(a%b)/b ;
Michel.

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

Nick wrote:
WholeMonths = TotalDays/30;
RemDays = TotalDays%30;
##### Quote
Pay = (WholeMonths * Rate) + ((RemDays / 30) * Rate);
More accurate:
Pay = (WholeMonths * Rate) + ((RemDays * Rate)/30.0);
Or even simpler:
Pay = (TotalDays * Rate )/30.0;

{smallsort}

## 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.
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.
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);

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

Chris, I believe that I read somewhere that Accountancy software uses
BCD maths as there are then NO rounding errors. Of course you do
need to find some BCD maths classes.....
Rgds Pete
"Chris Uzdavinis (TeamB)" < XXXX@XXXXX.COM >wrote in message
##### Quote
"Nick" < XXXX@XXXXX.COM >writes:

>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.

>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.

If you're getting weird results, I again ask for code to demonstrate
what you're doing that reproduces the problem.

>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.

>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.

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);

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

"Pete Fraser" < XXXX@XXXXX.COM >wrote:
##### Quote
Chris, I believe that I read somewhere that Accountancy software uses
BCD maths as there are then NO rounding errors. Of course you do
need to find some BCD maths classes.....
[followed by the entire 55-line previous post quoted]
Pete - you should know by now about the quoting rules.
Alan Bellingham
--
ACCU Conference 2006 - 19-22 April, Randolph Hotel, Oxford, UK

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

Grovel.....sorry
Pete
"Alan Bellingham" < XXXX@XXXXX.COM >wrote in message
##### Quote
"Pete Fraser" < XXXX@XXXXX.COM >wrote:

>Chris, I believe that I read somewhere that Accountancy software uses
>BCD maths as there are then NO rounding errors. Of course you do
>need to find some BCD maths classes.....

[followed by the entire 55-line previous post quoted]

Pete - you should know by now about the quoting rules.

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

"Pete Fraser" < XXXX@XXXXX.COM >writes:
##### Quote
Chris, I believe that I read somewhere that Accountancy software uses
BCD maths as there are then NO rounding errors. Of course you do
need to find some BCD maths classes.....
Microdollars are sufficient for our needs, for now. :)
--
Chris (TeamB);

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

Pete Fraser wrote:
##### Quote
Chris, I believe that I read somewhere that Accountancy software uses
BCD maths as there are then NO rounding errors. Of course you do
need to find some BCD maths classes.....
Rgds Pete
There is always the potential for rounding errors.
Even in the real world.
How much do you pay at a 1/3-off sale?
The good thing about BCD is you don't get extra rounding problems from
add/ subtract. And rounding rules are a bit easier to define.
As for finding classes... The old BC++ came with a BCD class.
I've been using Intel's built-in BCD codes since they came out with
the 8080 28 years ago, but I use fixed accuracy, and automatic
rounding for mul/div (and trucation of MSD for overflow).