// <!--
function calcul(dure1, taux1){

		var y, x, z, tauxms1, res;
		
		y = dure1 * 12;
		tauxms1 = taux1 / 1200;
		x = Math.pow((1 + tauxms1), y);
		z = 1 / x;
		res = tauxms1 / (1 - z) ;
		return (res); 
}

function arrondi (val, decs){
	
	multiplier = 10
    for (var i = 1; i < decs; ++i)
        multiplier = multiplier * 10
    // Convert the value to a string
    var strVal = val.toString()
    // Locate the decimal point
    var decimal = strVal.indexOf(".")
    // Is it the first character?
    if (decimal == 0)
        // If so, append a 0
        {
        strVal = "0" + strVal
        ++decimal
        }
    // See if the value is a whole number
    if (decimal != -1)
        {
        // If it isn't, grab the part to the left of the decimal
        var strWhole = strVal.substring(0, decimal)
        // Grab the decimal part
        var strDecimals = strVal.substring(decimal, strVal.length)
        //alert ("strDecimals est : " + strDecimals);
       // alert ("strdecimal.length de mes decimals est: " + strDecimals.length);
        if ((strDecimals.length - 1) != decs)
        {
		  // Multiply so we can use Math.round
			var valDecimals = eval (strDecimals * multiplier)
			//alert  ("le nbr à arrondir est valdecimals: " + valDecimals);
			
			//repérer la longueur de l'entier à arrondir
			var valDecimalstring = valDecimals.toString()
			var decimal2 = valDecimalstring.indexOf(".")
			var valdec2 = valDecimalstring.substring(0, decimal2);
									
			//alert  ("valDecimals.toString().length est : " + valDecimals.toString().length);
			// Calculate the number of leading zeroes in the decimals
			//var valLeftPadding = strDecimals.length - valDecimals.toString().length
			var valLeftPadding = 0
			for (j = 1;  j < strDecimals.length;  j++)
			
				if (strDecimals.charAt(j) == "0")
					valLeftPadding += 1;
				else
					break;	
				
			//alert  ("le nbr de zero après la virgule est : " + valLeftPadding);
			// Round it off
			var valDecimals = Math.round(valDecimals)
			// Convert the decimals back to a string
			strDecimals = valDecimals.toString()
			//alert  ("parti décimale après arrondissement et sans zero est (valdecimals) : " + strDecimals);
			
			// Handle the "0" case
			if (strDecimals == "0")
            {
				for (var i = 1; i < decs; ++i)
					strDecimals = strDecimals + "0"
            }
            
            var stock = strDecimals;
			//traiter le cas d'arrondir 9.89... ou 99.89...
			//if (strDecimals.length > valdec2.length)
				//if (valLeftPadding != 0)
					
			
			// Restore the leading zeroes in the decimals, if any
            for (i = 1; i <= valLeftPadding; ++i)
                strDecimals = "0" + strDecimals
                
            if (strDecimals.length > decs){
				//alert (strDecimals.length + ">" + decs);
				if (valLeftPadding != 0)
				{
					valLeftPadding = valLeftPadding - 1;
					//alert ("stcko= " + stock + "valLeftPadding= " + valLeftPadding);
					strDecimals = stock;
					for (i = 1; i <= valLeftPadding; ++i)
						strDecimals = "0" + strDecimals;
				}
				else
				{
					var nbw = eval (parseInt(strWhole) + 1);
					strWhole = nbw.toString();
					strDecimals = "";
					for (i = 1; i <= decs; ++i)
						strDecimals = "0" + strDecimals;
				}
			}
         }
         else
			return parseFloat(val);
        }
    else
        {
        // The integer part is the entire value
        var strWhole = strVal
        // Create the decimal part by padding with zeroes
        var strDecimals = ""
        for (var i = 1; i <= decs; ++i)
            strDecimals = strDecimals + "0"
        }
        
        
    // Put everything back together again
    var strRounded = strWhole + "." + strDecimals
    return (strRounded);
}

/*function calcul2(dure1, taux1){
	
	tauxms1 = taux1 / 1200;
	x = Math.pow((1 + tauxms1), dure1);
	z = 1 / x;
	res = tauxms1 / (1 - z) ;
	return (res);
}*/

// -->
