Decimal number class
-
Does anyone know of a (preferably free) class library that will accurately represent decimal numbers? we have been using floats but these have problems representing certain numbers and are resulting in rounding errors.
-
could you explain a bit more ? i don't understand why you're talking about a class for integers. don't you want to use
signed
/unsigned
int
/short
/long
??
TOXCCT >>> GEII power
-
No I mean decimal numbers, like 1.234 float and double are no good at representing certain values (e.g. 0.1) I need a class that can accruately represent decimal numbers
Instead of
float
(4 bytes), usedouble
(8 bytes) orlong double
(10 bytes) if you need even more precision -
No I mean decimal numbers, like 1.234 float and double are no good at representing certain values (e.g. 0.1) I need a class that can accruately represent decimal numbers
-
Does anyone know of a (preferably free) class library that will accurately represent decimal numbers? we have been using floats but these have problems representing certain numbers and are resulting in rounding errors.
Here's a commercial one: Base One Number Class
-
did you have a look at float.h ? you certainly didn't. you will find many "tools" to manage non real values like infinites, resolution loose, and so... and about your 0.1, i don't understand why float is not good...
TOXCCT >>> GEII power
toxcct wrote: and about your 0.1, i don't understand why float is not good... float and double are nice containers for floating point numbers, but they aren't accurate, they can't accurately describe 2 1/3 for example. While double is ok for most apps, it would be a poor choice for eg. insurance companies where the roundings in the complex actuarial formulas would mean filtering away billions of dollars. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
-
Does anyone know of a (preferably free) class library that will accurately represent decimal numbers? we have been using floats but these have problems representing certain numbers and are resulting in rounding errors.
Technically, decimal means base-10 (deca is Greek for ten). So, rather than using a
float
type, are you wanting to use anint
type? If you simply need more precision, you might try the DECIMAL type. However, I suspect you are not having precision problems. Most beginners assume you can compare floating-point numbers just like you can non floating-point numbers. For example, this would never produce the desired result:float a = 0.1;
if (a == 0.1)
...because
a
is stored internally as 0.0999999999, give or take a few 9s.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow