Discussion:
BCD problems...
(too old to reply)
Gene Buckle
2008-06-17 03:57:53 UTC
Permalink
I'm trying to convert a double to BCD, and all I'm getting for my
trouble are exceptions.

example:

TBcd bcdData;
double doubleData;

(doubleData in this case is 4.24399209022528E-313)

bcdData = DoubleToBcd(doubleData) results in an exception complaining that the
stated value isn't a valid BCD value. The documentation for the this routine
is completely inadequate and searches on the net haven't been helpful.

What I don't get is if it can reasonably fit in a double, why the hell can't
it be converted? Is there a way around this? I certainly can't change the
number because it's coming from an external source.

Any help will be hugely appriciated.

tnx.

g.
--
Proud owner of F-15C 80-0007
http://www.f15sim.com - The only one of its kind.
Eelke
2008-06-17 06:35:53 UTC
Permalink
The TBcd class cannot store the value you specify because of the large
negative exponent. A TBcd doesn't have an exponent and the conversion
routine you use will not use more then 15 digits.

However I do not understand why they not simply round it to the closest
value they can store which is zero.

Depending on your need of precision you might be able to solve this by
rounding your values to a specific precision or if all values are very
small by scaling them into a more suitable range.

If the scale of values u have to store varies greatly you might be
better of searching for a class for decimal values with exponent or just
use doubles.


Eelke
Post by Gene Buckle
I'm trying to convert a double to BCD, and all I'm getting for my
trouble are exceptions.
TBcd bcdData;
double doubleData;
(doubleData in this case is 4.24399209022528E-313)
bcdData = DoubleToBcd(doubleData) results in an exception complaining that the
stated value isn't a valid BCD value. The documentation for the this routine
is completely inadequate and searches on the net haven't been helpful.
What I don't get is if it can reasonably fit in a double, why the hell can't
it be converted? Is there a way around this? I certainly can't change the
number because it's coming from an external source.
Any help will be hugely appriciated.
tnx.
g.
Gene Buckle
2008-06-17 15:12:50 UTC
Permalink
Post by Eelke
The TBcd class cannot store the value you specify because of the large
negative exponent. A TBcd doesn't have an exponent and the conversion
routine you use will not use more then 15 digits.
However I do not understand why they not simply round it to the closest
value they can store which is zero.
Depending on your need of precision you might be able to solve this by
rounding your values to a specific precision or if all values are very
small by scaling them into a more suitable range.
If the scale of values u have to store varies greatly you might be
better of searching for a class for decimal values with exponent or just
use doubles.
Eelke
Thanks for the reply Eelke. It turns out that I don't think really well
with a pinched nerve in my neck. :) The whole problem went away when I
started using an unsigned integer for the starting value. The process
began showing the expected data.

g.
--
Proud owner of F-15C 80-0007
http://www.f15sim.com - The only one of its kind.
Loading...