
    function Fraction(x,y) {

        this.num = x ;
        this.den = y ;

        if (this.num >= this.den) {
	    this.whole = Math.floor(eval(this.num/this.den)) ;
	    this.num   = this.num  - this.whole*this.den     ;
	} else {
            this.whole = ""                                  ;
	}
        this.reduce() ; 
	
    }
   
    Fraction.prototype.decimal = function(position) {
        if ((position == null) || (position == undefined)) {
            position = 4 ;
        }
        this.value = eval(parseInt(this.whole) + parseInt(this.num)/parseInt(this.den)) ;
        this.value = fround(this.value, position) ;
	return(String(this.value)) ;    
    }

    Fraction.prototype.percent = function(position) {
 
    if ((position == null) || (position == undefined)) {
        position = 4 ;
    }
        this.value = eval(parseInt(this.whole) + parseInt(this.num)/parseInt(this.den)) ;
        this.value = fround(this.value, position) ;
//	return(String(this.value*100)+"%") ;
        return(String(this.value*100)) ;
    }

    Fraction.prototype.mixed = function() {
		
        if (this.whole > 0) {
            space = "  "                                     ;
	} else {
	    space      = ""                                  ;
	}
	return (String(this.whole) + space + String(this.num) + "/" + String(this.den)) ;
    } 
   
    Fraction.prototype.reduce = function() {
        var a = parseInt(this.num) ;
        var b = parseInt(this.den) ;
        var tempA             ;
        var tempB             ;
        var i                 ;
	       
        for (i = 0 ; prime[i] <= this.num; i++) {
            tempA = a/prime[i] ;
            if ((tempA - Math.floor(tempA)) == 0) {
                tempB = b/prime[i] ;
                if ((tempB - Math.floor(tempB)) == 0) {
		    this.num = tempA ;
		    this.den = tempB ; 
                    this.reduce() ;    
                    return ;
                }
            }
        }
    }
    
    Fraction.prototype.toString = function() {
       return (String(this.whole) + "  " + String(this.num) + "/" + String(this.den)) ;   
    }
   
   function Decimal( x ) {
       this.whole         = new Number() ; // the whole portion of the number
       this.num           = new Number() ; // the numerator of the equivalent to the decimal portion of the number.
       this.den           = new Number() ; // the denominator of the equivalent to the decimal portion of the number.
       this.decimal       = new Number() ; // the decimal portion of the number.
       this.decimalpoint  = new Number() ; // location of the decimal point in the number.
       this.decimalLength = new Number() ; // the length of the decimal portion of the number
       this.value         = new Number() ; // the full value of the original number.
       this.str           = new String() ; // the string version of the original number.
       
       if (isNaN(x) == true) {
           x = ""                                                              ;
       }
       this.assign(x)                                                          ;
   }

   Decimal.prototype.assign = function(x) {

       this.str = x                                                            ;
       this.decimalpoint = (this.str).indexOf(".", 0)                          ;
       this.value = x                                                          ;
       if (this.decimalpoint > -1) {
           this.whole = this.str.slice(0,this.decimalpoint)                    ;
           this.decimal = this.str.slice(this.decimalpoint+1, this.str.length) ;	   
	   this.decimalLength = this.str.length - (this.decimalpoint+1)        ;

       } else {
           this.whole = this.str                                               ;
	   this.decimal = ""                                                   ;
       }
   }
   
   Decimal.prototype.percent = function () {
       return (this.value*100)                                                 ; 
   }
   
   Decimal.prototype.decimal = function () {
       return (this.value)                                                     ;    
   }
   
   Decimal.prototype.toString = function() {
       return (this.str)                                                       ;
   }
   
   var divisor = new Array(1, 10, 100, 1000, 10000, 100000)                    ;
   Decimal.prototype.fraction = function() {

	var space                                                              ;
	this.num = this.decimal                                                ;

        this.den = divisor[this.decimalLength]                                 ;
        this.reduce()                                                          ;
        return (Number(this.num) + "/" + Number(this.den))                     ;

    } 
   
    Decimal.prototype.mixed = function() {
        var space                                                              ;
	var whole                                                              ;

	this.num = this.decimal                                                ;
	this.den = divisor[this.decimalLength]                                 ;

	if (this.num > 0) {
	    this.reduce()                                                      ;
	}
	if (this.whole == 0) {
            whole = ""                                                         ;
	    space = ""                                                         ;
	} else {
	    whole = this.whole                                                 ;
            space = "  "                                                       ;
	}
	if (this.num == 0) {
	    return (this.whole)                                                ;
	} else {
	    return (whole + " " + Number(this.num) + "/" + Number(this.den))   ;
	}
    }
    
    Decimal.prototype.reduce = function() {
        var a = parseInt(this.num)                                             ;
        var b = parseInt(this.den)                                             ;
        var tempA                                                              ;
        var tempB                                                              ;
        var i                                                                  ;
	       
        for (i = 0 ; prime[i] <= this.num; i++) {
            tempA = a/prime[i]                                                 ;
            if ((tempA - Math.floor(tempA)) == 0) {
                tempB = b/prime[i]                                             ;
                if ((tempB - Math.floor(tempB)) == 0) {
		    this.num = tempA                                           ;
		    this.den = tempB                                           ; 
                    this.reduce()                                              ;    
                    return                                                     ;
                }
            }
        }
    }

   
   function Percent() {
       this.value = new Decimal() ;
       this.value = 0 ;
   }
   
   function Percent( x ) {
       this.num           = 0                                                  ;
       this.den           = 0                                                  ;
       this.whole         = 0                                                  ;
       this.decimalpoint  = 0                                                  ;
       this.decimalLength = 0                                                  ;
       
       this.value         = new Decimal() ;  // This is the decimal that is displayed next to the percent sign,
                                            //     it is not the decimal equivalent of the percent.
       var percentsign    = new Number()                                       ;
       var str            = x                                                  ;
    
       if ((x == null) || (x == undefined)) {
           str = ""                                                            ;
       }

       this.assign(str)                                                        ;          
   }

   Percent.prototype.assign = function (x) {
   
      var str = new String()                                                   ;
      str = x                                                                  ;
      this.decimalpoint = (str).indexOf(".",0)                                 ;
      percentsign = (str).indexOf("%",0)                                       ;
       if (percentsign > 0) {
           str = (str).slice(0,percentsign)                                    ;
       }

       this.value = str                                                        ;
       this.str   = str                                                        ;
       if (this.decimalpoint > -1) {
           this.whole = this.str.slice(0, this.decimalpoint)                   ;
	   this.decimal = this.str.slice(this.decimalpoint+1, this.str.length) ;
	   this.decimalLength = this.str.length - (this.decimalpoint+1)        ;
       } else {
           this.whole = this.str                                               ;
	   this.decimal = ""                                                   ;
       }
   
   }

   Percent.prototype.decimal = function () {
       return ((this.value)/100)                                               ;   
   }

   Percent.prototype.percent = function () {
       return (this.value)                                                     ;
   }
   
   Percent.prototype.toString = function () {
       return (this.value + "%")                                             ;
   }
 
   var prime = new Array(2,3,5,7,11,13,17,19,23,29,31,37,41,43)                ;
   
   Percent.prototype.fraction = function() {
        this.num = parseInt(this.value)                                        ;
        this.den = divisor[2 + this.decimalLength]                             ;
        this.reduce()                                                          ;
	return (String(this.num) + "/" + String(this.den))                     ;
    } 

   Percent.prototype.mixed = function() {

	var decimal                                                            ;
	var space                                                              ;
	this.num = this.whole + this.decimal                                   ;
	this.den = divisor[2+this.decimalLength]                               ;

	
        if (this.num >= this.den) {
	    this.whole = Math.floor(eval(this.num/this.den))                 ;
	    this.num   = this.num - this.whole*this.den
            space = "  "                                                       ;
	} else {
            this.whole = ""                                                    ;
	    this.num   = Number(this.num)                                      ;
	    space      = ""                                                    ;
	}

        this.reduce() ;
	return (String(this.whole) + space + String(this.num) + "/" + String(this.den)) ;
    } 

    Percent.prototype.xmixed = function() {
        var space                                                              ;
	var whole                                                              ;

	this.num = this.decimal                                                ;
	this.den = divisor[this.decimalLength]                                 ;

	if (this.num > 0) {
	    this.reduce()                                                      ;
	}
	if (this.whole == 0) {
            whole = ""                                                         ;
	    space = ""                                                         ;
	} else {
	    whole = this.whole                                                 ;
            space = "  "                                                       ;
	}
	if (this.num == 0) {
	    return (this.whole)                                                ;
	} else {
	    return (whole + " " + Number(this.num) + "/" + Number(this.den))   ;
	}
    }

    Percent.prototype.reduce = function() {
        var a = parseInt(this.num) ;
        var b = parseInt(this.den) ;
        var tempA             ;
        var tempB             ;
        var i                 ;
	       
        for (i = 0 ; prime[i] <= this.num; i++) {
            tempA = a/prime[i] ;
            if ((tempA - Math.floor(tempA)) == 0) {
                tempB = b/prime[i] ;
                if ((tempB - Math.floor(tempB)) == 0) {
		    this.num = tempA ;
		    this.den = tempB ; 
                    this.reduce() ;    
                    return ;
                }
            }
        }
    }

