12,828,907 members (47,251 online)
alternative version

#### Stats

55.5K views
16 bookmarked
Posted 19 Nov 2002

# CDFValue - Fractional/Decimal conversion class

, 22 Nov 2002
 Rate this:
A class used to manipulate and convert decimal and fractional data.

As a remodeling professional and an avid woodworking enthusiast I realized, after many hours of searching the net for woodworking software that there was a need for applications that specialize in this area. Therefore I came to the conclusion that I would either have to wait for someone else to develop them, pay their price and hope they had the functionality that I needed or develop them myself and integrate the functionality I needed into my apps.

I determined that the first place to start was to develop a class to handle decimal and fractional data with the ability to convert between the two. Therefore I created the `CDFValue` class. This class encapsulates this functionality and provides a rich set of methods providing the user with the ability to handle decimal, fractional and a mixture of both data types and to be able to manipulate and convert this data.

In the example below the local variable `gbl_precision` is used to define the required precision. In my applications I use this variable as a global and allow the user to set it to either 1/16", 1/32" or 1/64". In the example I set it at 1/64". If units not given they are assumed to be in feet.

```int gbl_precision = 64;

CDFValue DFVal1;
CDFValue DFVal2;
CDFValue DFRes;
CString  strVal1 = "1'6\"";

DFVal1.SetDFValue(strVal1);
DFVal2.SetDFValue(1.5);

DFRes = DFVal1 + DFVal2;  //DFRes = 3'
DFRes = DFVal1 - DFVal2;  //DFRes = 0
DFRes = DFVal1 * DFVal2;  //DFRes = 2'3"
DFRes = DFVal1 / DFVal2;  //DFRes = 1
DFVal1 == DFVal2;		  //TRUE
```

As you can see from the example the `CDFValue` class is easy to use and very versatile. Values may be in fractional

```80", 5', 5'6", 5'6-1/2"
```

in decimal

`.15, 1, 1.5`

or a mixture of the two

`12.5", 1.5'`

Thats all there is to it!

You may use this class freely, the only thing I ask is that if you like this class and use it you give credit where credit is due. i.e. Treat me as I would treat you.

A list of licenses authors might use can be found here

## Share

 Web Developer United States
No Biography provided

## You may also be interested in...

 First Prev Next
 A little work.. CanopenR18-Dec-08 11:37 CanopenR 18-Dec-08 11:37
 New Interface reichj23-Sep-06 4:46 reichj 23-Sep-06 4:46
 Or Ryan S Roberts22-Nov-02 1:59 Ryan S Roberts 22-Nov-02 1:59
 Re: Or Old Timer22-Nov-02 10:36 Old Timer 22-Nov-02 10:36
 Missing links... Marc Clifton20-Nov-02 2:35 Marc Clifton 20-Nov-02 2:35
 Re: Missing links... Uwe Keim20-Nov-02 2:47 Uwe Keim 20-Nov-02 2:47
 Re: Missing links... Old Timer20-Nov-02 10:32 Old Timer 20-Nov-02 10:32
 Yes, much better Marc Clifton22-Nov-02 9:31 Marc Clifton 22-Nov-02 9:31
 Aaah ... Anonymous20-Nov-02 2:33 Anonymous 20-Nov-02 2:33
 Re: Aaah ... Marc Clifton20-Nov-02 2:36 Marc Clifton 20-Nov-02 2:36
 Re: Aaah ... Drew Stainton21-Nov-02 4:39 Drew Stainton 21-Nov-02 4:39
 Last Visit: 31-Dec-99 19:00     Last Update: 29-Mar-17 11:03 Refresh 1