Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / MFC
Article

CDFValue - Fractional/Decimal conversion class

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
22 Nov 20021 min read 62.1K   707   16   11
A class used to manipulate and convert decimal and fractional data.

Sample Image - DFValue_ss.jpg

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralA little work.. Pin
CanopenR18-Dec-08 10:37
CanopenR18-Dec-08 10:37 
GeneralNew Interface Pin
reichj23-Sep-06 3:46
reichj23-Sep-06 3:46 
GeneralOr Pin
Ryan_Roberts22-Nov-02 0:59
Ryan_Roberts22-Nov-02 0:59 
GeneralRe: Or Pin
Old Timer22-Nov-02 9:36
Old Timer22-Nov-02 9:36 
GeneralMissing links... Pin
Marc Clifton20-Nov-02 1:35
mvaMarc Clifton20-Nov-02 1:35 
GeneralRe: Missing links... Pin
Uwe Keim20-Nov-02 1:47
sitebuilderUwe Keim20-Nov-02 1:47 
GeneralRe: Missing links... Pin
Old Timer20-Nov-02 9:32
Old Timer20-Nov-02 9:32 
GeneralYes, much better Pin
Marc Clifton22-Nov-02 8:31
mvaMarc Clifton22-Nov-02 8:31 
GeneralAaah ... Pin
20-Nov-02 1:33
suss20-Nov-02 1:33 
GeneralRe: Aaah ... Pin
Marc Clifton20-Nov-02 1:36
mvaMarc Clifton20-Nov-02 1:36 
GeneralRe: Aaah ... Pin
Drew Stainton21-Nov-02 3:39
Drew Stainton21-Nov-02 3:39 
From dictionary.com...

me·ter2
n. Abbr. m
The international standard unit of length, approximately equivalent to 39.37 inches. It was redefined in 1983 as the distance traveled by light in a vacuum in
1/299,792,458 of a second.
No more meridian stuff - it's pretty accurate now.

Drew.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.