function number_format( number, decimals, dec_point, thousands_sep ) { // http://kevin.vanzonneveld.net // + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + bugfix by: Michael White (http://getsprink.com) // + bugfix by: Benjamin Lupton // + bugfix by: Allan Jensen (http://www.winternet.no) // + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) // + bugfix by: Howard Yeend // + revised by: Luke Smith (http://lucassmith.name) // + bugfix by: Diogo Resende // + bugfix by: Rival // % note 1: For 1000.55 result with precision 1 in FF/Opera is 1,000.5, but in IE is 1,000.6 // * example 1: number_format(1234.56); // * returns 1: '1,235' // * example 2: number_format(1234.56, 2, ',', ' '); // * returns 2: '1 234,56' // * example 3: number_format(1234.5678, 2, '.', ''); // * returns 3: '1234.57' // * example 4: number_format(67, 2, ',', '.'); // * returns 4: '67,00' // * example 5: number_format(1000); // * returns 5: '1,000' // * example 6: number_format(67.311, 2); // * returns 6: '67.31' var n = number, prec = decimals; n = !isFinite(+n) ? 0 : +n; prec = !isFinite(+prec) ? 0 : Math.abs(prec); var sep = (typeof thousands_sep == "undefined") ? ',' : thousands_sep; var dec = (typeof dec_point == "undefined") ? '.' : dec_point; var s = (prec > 0) ? n.toFixed(prec) : Math.round(n).toFixed(prec); //fix for IE parseFloat(0.55).toFixed(0) = 0; var abs = Math.abs(n).toFixed(prec); var _, i; if (abs >= 1000) { _ = abs.split(/\D/); i = _[0].length % 3 || 3; _[0] = s.slice(0,i + (n < 0)) + _[0].slice(i).replace(/(\d{3})/g, sep+'$1'); s = _.join(dec); } else { s = s.replace('.', dec); } return s; } function isDifferentCurrencies() { //return ( != ); return 1; } function updateCurrency() { document.getElementById( "onLineCurrencyValue" ).value = ""; document.getElementById( "onLineCurrency" ).value = ""; } function putAllCurrency() { var nLoop = 0; while ( nLoop < __currency.length ) { if ( isDifferentCurrencies() ) { if ( __currency[ nLoop ] !=null ) { var curr = "curr_" + nLoop; var rate = document.getElementById( "cr_" + nLoop ).value; // THIS USED TO USE FUNCTION apply_change_rate_global WITH AN 'R' AS THIRD PARAMETER // BUT WAS CHANGED TO ALLOW ceil FUNCTION USAGE // WE NEED TO REMOVE '.' THOUSANDS SEPARATOR AND REPLACE ',' DECIMALS SEPARATOR WITH '.' // SO THE STRING IS CORRECTLY PARSED AS FLOAT FOR CEILING // 11/05/10 // By Peraza if (rate != 1){ // ration has been calculated before, only is necessary to apply it document.getElementById( curr ).innerHTML = Math.ceil(__currency[ nLoop ] * rate) + "" ; } } } nLoop++; } var nLoop = 0; while ( nLoop < __currency_bis.length ) { if ( __currency_bis[ nLoop ] !=null ) { var curr = "curr_bis_" + nLoop; var rate = document.getElementById( "cr_bis_" + nLoop ).value; // SUPPORT FOR ADDITIONAL RESULTS // 31/05/10 // By Peraza document.getElementById( curr ).innerHTML = Math.ceil(parseFloat(apply_change_rate (__currency_bis[ nLoop ], rate).replace('.','').replace(',','.'))) + ""; } nLoop++; } var nLoop = 0; while ( nLoop < __currency_2.length ) { if ( __currency_2[ nLoop ] !=null ) { var curr = "curr_2_" + nLoop; if (document.getElementById( "cr_2_" + nLoop )){ var rate = document.getElementById( "cr_2_" + nLoop ).value; // SUPPORT FOR ADDITIONAL ADDITIONAL RESULTS (Don't you love reverse engineering?) // 31/05/10 // By Peraza document.getElementById( curr ).innerHTML = Math.ceil(parseFloat(apply_change_rate (__currency_2[ nLoop ], rate).replace('.','').replace(',','.'))) + "€"; } } nLoop++; } // alert ( "input_curr_one = " + document.getElementById( "input_curr_one" ).value + "\ninput_rate_one = " + document.getElementById( "input_rate_one" ).value + "\ninput_curr_two = " + document.getElementById( "input_curr_two" ).value + "\ninput_rate_two = " + document.getElementById( "input_rate_two" ).value ); if ( document.getElementById( "best_rated" ) ) { document.getElementById( "best_rated_div" ).innerHTML = document.getElementById( "best_rated" ).value; var add_class = ""; var elem_class = document.getElementById( "priceCalculatorTop" ); elem_class.className += ' ' + 'twoPrices'; if (document.getElementById( "input_curr_two" ) && document.getElementById( "input_curr_two" ).value != -1) { document.getElementById( "curr_two" ).innerHTML = '' + Math.ceil(parseFloat(apply_change_rate (document.getElementById( "input_curr_two" ).value, document.getElementById( "input_rate_two" ).value).replace(/\./g,'').replace(',','.'))) + "" + ''; } else { add_class = "onlyOnePrice"; if ( ( (' ' + elem_class.className + ' ').indexOf(' ' + 'twoPrices' + ' ') > -1 ) === true ) elem_class.className = elem_class.className.replace(/(?:^|\s)twoPrices(?!\S)/g, ""); } document.getElementById( "curr_one" ).innerHTML = '' + Math.ceil(parseFloat(apply_change_rate (document.getElementById( "input_curr_one" ).value, document.getElementById( "input_rate_one" ).value).replace(/\./g,'').replace(',','.'))) + "" + ''; if (add_class != '') document.getElementById( "best_rated_div" ).className += ' ' + add_class; } if ( document.getElementById( "price_range" ) ) { var curr_three = document.getElementById( "curr_three" ); var curr_four = document.getElementById( "curr_four" ); if (curr_three) curr_three.innerHTML = Math.ceil(parseFloat(apply_change_rate (document.getElementById( "input_curr_three" ).value, document.getElementById( "input_rate_three" ).value).replace(/\./g,'').replace(',','.'))) + ""; if (curr_four) curr_four.innerHTML = Math.ceil(parseFloat(apply_change_rate (document.getElementById( "input_curr_four" ).value, document.getElementById( "input_rate_four" ).value).replace(/\./g,'').replace(',','.'))) + ""; } } function apply_change_rate( total, rate_org ) { } function apply_change_rate_text( total, rate, curr_position ) { return "( " + apply_change_rate_text_global( total, rate, curr_position ) + " )"; } function apply_change_rate_text_global( total, rate, curr_position ) { var res = ""; if ( curr_position == "L" ) { res += " "; } res += apply_change_rate( total, rate ); if ( curr_position == "R" ) { res += " "; } return res; }