js汇率换算器代码

js汇率换算器代码,js汇率换算代码编写教程如下:

选额需要兑换的数字和币种

计算结果:根据汇率换算出对应的金额

js实现代码:

function presentValue(fv,freq,rate,periods)
{return(fv/Math.pow((1+(rate/100/freq)),periods));}
function futureValue(pv,freq,rate,periods)
{return(pv*Math.pow(1+(rate/100/freq),periods));}
function annualizedReturn(fv,pv,years)
{return(fv-pv)/pv/years;}
function monthlyPayment(pv,freq,rate,periods)
{rate=rate/100/freq;var x=Math.pow(1+rate,periods);return(pv*x*rate)/(x-1);}
function annuity(fv,freq,rate,periods)
{rate=rate/100/freq;return(fv/((Math.pow(1+rate,periods)-1))*rate);}
function calcAmortPrincipal(pymt,freq,rate,periods)
{rate=rate/100/freq;return(pymt*(1-(1/Math.pow(1+rate,periods)))/rate);}
function toCurrency(num){num=Math.round(num*100)/100;var currstring=num.toString();if(currstring.match(/\./)){var curr=currstring.split('.');}else{var curr=[currstring,"00"];}
curr[1]+="00";curr[2]="";var returnval="";var length=curr[0].length;for(var i=0;i<2;i++)
curr[2]+=curr[1].substr(i,1);for(i=length;(i-3)>0;i=i-3){returnval=","+curr[0].substr(i-3,3)+returnval;}
returnval=curr[0].substr(0,i)+returnval+"."+curr[2];return(returnval);}
function regularDeposit(payment,freq,rate,periods)
{rate=rate/100/freq;return(payment*(Math.pow(1+rate,periods)-1)/rate*(1+rate));}

window.onload=function(){var from_tkc=document.currcalc.from_tkc;var to_tkc=document.currcalc.to_tkc;var huilv1=document.getElementById("huilv1");var huilv2=document.getElementById("huilv2");if(!isEmpty(huilv1)){calculate(from_tkc,to_tkc,"huilv1")}if(!isEmpty(huilv2)){calculate(to_tkc,from_tkc,"huilv2")}};var eurovals=new Object();eurovals.FRF=6.559;eurovals.ATS=13.7603;eurovals.PTE=200.482;eurovals.ESP=166.386;eurovals.BEF=40.3399;eurovals.NLG=2.20371;eurovals.FIM=5.94573;eurovals.DEM=1.95583;eurovals.IEP=0.78756;eurovals.ITL=1936.27;eurovals.LUF=40.3399;eurovals.GRD=340.75;function calculate(from_tkc,to_tkc,id){var l=isEmpty(from_tkc)?document.currcalc.from_tkc:from_tkc;var k=isEmpty(to_tkc)?document.currcalc.to_tkc:to_tkc;var id=isEmpty(id)?"crncyres":id;var c=l[l.selectedIndex].text;var i=k[k.selectedIndex].text;var d;var a;var j=document.currcalc.translation1.value;var h=document.currcalc.translation2.value;var f=document.currcalc.translation3.value;if(c.match(/\(EUR\)/)!=null){var o=i.split("(");var n=o.length-1;var p=o[n].match(/(FRF|ATS|PTE|ESP|BEF|NLG|FIM|DEM|IEP|ITL|LUF|GRD)/);if(p!=null){d=1;a=eurovals[p[0]]}}if(i.match(/\(EUR\)/)!=null){var e=c.split("(");var b=e.length-1;var p=e[b].match(/(FRF|ATS|PTE|ESP|BEF|NLG|FIM|DEM|IEP|ITL|LUF|GRD)/);if(p!=null){a=1;d=eurovals[p[0]]}}if(d==null&&a==null){d=price[l[l.selectedIndex].value];a=price[k[k.selectedIndex].value]}if((d<0)||(d=="")||isNaN(d)||(a<0)||(a=="")||isNaN(a)){alert(j);return false}var g=document.currcalc.amount.value;if((g=="")||isNaN(g)||(g==0)||(g<1)){alert(h);document.currcalc.amount.focus();return false}var m=/,/g;g=g.replace(m,"");ShowResult(d,a,g,l,k,id)}function ShowResult(e,c,f,l,k,id){var i=f*c/e;var h=l;var g=k;var d=document.currcalc.translation.value;var b='<span class="style4">'+f+" "+h.options[h.selectedIndex].text+" = "+round(i)+" "+g.options[g.selectedIndex].text+"</span>";if((navigator.appName.indexOf("Netscape")!=-1)&&(parseInt(navigator.appVersion)==4)){var a=document.layers.crncyres2.document;a.open();a.write(b);a.close()}else{if((navigator.appName.indexOf("Microsoft")!=-1)||(parseInt(navigator.appVersion)>=5)){document.getElementById(id).innerHTML=b}else{alert(errmsg3)}}}function round(a){if(a<200000){return Math.round(a*10000)/10000}else{if(a<20000000){return Math.round(a*100)/100}else{return Math.round(a)}}}function NS47_addlines(){var a;if((navigator.appName.indexOf("Netscape")!=-1)&&(parseInt(navigator.appVersion)==4)){for(a=0;a<10;a++){document.write("<br>")}}}function loadResults(){if((navigator.appName.indexOf("Netscape")!=-1)&&(parseInt(navigator.appVersion)==4)){document.write('<DIV ID="crncyres2"></DIV>')}else{document.write('<DIV ID="crncyres"></DIV>')}}function isEmpty(v){if(v==null){return true}else{if(v=="null"){return true}else{if(v==undefined){return true}else{if(v=="undefined"){return true}else{if(v==""){return true}else{if(v=="请选择"){return true}else{return false}}}}}}};

var price = new Object();
price[
'AED:CUR'] = 3.6726; price[
'AFN:CUR'] = 87.596895; price[
'ALL:CUR'] = 103.091329; price[
'AMD:CUR'] = 385.098294; price[
'ANG:CUR'] = 1.802425; price[
'AOA:CUR'] = 567.14441; price[
'ARS:CUR'] = 238.237745; price[
'AUD:CUR'] = 1.528529; price[
'AWG:CUR'] = 1.8025; price[
'AZN:CUR'] = 1.7; price[
'BAM:CUR'] = 1.825394; price[
'BBD:CUR'] = 2; price[
'BDT:CUR'] = 107.238841; price[
'BGN:CUR'] = 1.829434; price[
'BHD:CUR'] = 0.376935; price[
'BIF:CUR'] = 2821.514803; price[
'BMD:CUR'] = 1; price[
'BND:CUR'] = 1.35345; price[
'BOB:CUR'] = 6.910326; price[
'BRL:CUR'] = 5.0193; price[
'BSD:CUR'] = 1; price[
'BTC:CUR'] = 0.000035979862; price[
'BTN:CUR'] = 82.605716; price[
'BWP:CUR'] = 13.757024; price[
'BYN:CUR'] = 2.524384; price[
'BZD:CUR'] = 2.015905; price[
'CAD:CUR'] = 1.358508; price[
'CDF:CUR'] = 2327.73664; price[
'CHF:CUR'] = 0.904778; price[
'CLF:CUR'] = 0.029033; price[
'CLP:CUR'] = 801.15; price[
'CNH:CUR'] = 7.096342; price[
'CNY:CUR'] = 7.087; price[
'COP:CUR'] = 4440.989194; price[
'CRC:CUR'] = 538.277364; price[
'CUC:CUR'] = 1; price[
'CUP:CUR'] = 25.75; price[
'CVE:CUR'] = 102.919956; price[
'CZK:CUR'] = 22.135033; price[
'DJF:CUR'] = 178.069391; price[
'DKK:CUR'] = 6.958113; price[
'DOP:CUR'] = 54.714483; price[
'DZD:CUR'] = 136.835108; price[
'EGP:CUR'] = 30.8976; price[
'ERN:CUR'] = 15; price[
'ETB:CUR'] = 54.603781; price[
'EUR:CUR'] = 0.934189; price[
'FJD:CUR'] = 2.24725; price[
'FKP:CUR'] = 0.808004; price[
'GBP:CUR'] = 0.808004; price[
'GEL:CUR'] = 2.585; price[
'GGP:CUR'] = 0.808004; price[
'GHS:CUR'] = 11.25028; price[
'GIP:CUR'] = 0.808004; price[
'GMD:CUR'] = 59.6; price[
'GNF:CUR'] = 8597.071406; price[
'GTQ:CUR'] = 7.820499; price[
'GYD:CUR'] = 211.509826; price[
'HKD:CUR'] = 7.831817; price[
'HNL:CUR'] = 24.586048; price[
'HRK:CUR'] = 7.038967; price[
'HTG:CUR'] = 140.51575; price[
'HUF:CUR'] = 346.338864; price[
'IDR:CUR'] = 14985.476088; price[
'ILS:CUR'] = 3.712684; price[
'IMP:CUR'] = 0.808004; price[
'INR:CUR'] = 82.7355; price[
'IQD:CUR'] = 1309.132748; price[
'IRR:CUR'] = 42300; price[
'ISK:CUR'] = 139.47; price[
'JEP:CUR'] = 0.808004; price[
'JMD:CUR'] = 154.324302; price[
'JOD:CUR'] = 0.7099; price[
'JPY:CUR'] = 140.1664; price[
'KES:CUR'] = 138.5; price[
'KGS:CUR'] = 87.59; price[
'KHR:CUR'] = 4112.435978; price[
'KMF:CUR'] = 459.449734; price[
'KPW:CUR'] = 900; price[
'KRW:CUR'] = 1322.22869; price[
'KWD:CUR'] = 0.307592; price[
'KYD:CUR'] = 0.833399; price[
'KZT:CUR'] = 445.400966; price[
'LAK:CUR'] = 17691.600191; price[
'LBP:CUR'] = 15011.626558; price[
'LKR:CUR'] = 297.035742; price[
'LRD:CUR'] = 167.950028; price[
'LSL:CUR'] = 19.690678; price[
'LYD:CUR'] = 4.823686; price[
'MAD:CUR'] = 10.224838; price[
'MDL:CUR'] = 17.788934; price[
'MGA:CUR'] = 4406.442873; price[
'MKD:CUR'] = 57.518387; price[
'MMK:CUR'] = 2100.275409; price[
'MNT:CUR'] = 3519; price[
'MOP:CUR'] = 8.064813; price[
'MRU:CUR'] = 34.393317; price[
'MUR:CUR'] = 45.779997; price[
'MVR:CUR'] = 15.3; price[
'MWK:CUR'] = 1026.517426; price[
'MXN:CUR'] = 17.588233; price[
'MYR:CUR'] = 4.6075; price[
'MZN:CUR'] = 63.899991; price[
'NAD:CUR'] = 19.65; price[
'NGN:CUR'] = 460.800934; price[
'NIO:CUR'] = 36.577966; price[
'NOK:CUR'] = 11.134066; price[
'NPR:CUR'] = 132.173424; price[
'NZD:CUR'] = 1.652693; price[
'OMR:CUR'] = 0.384961; price[
'PAB:CUR'] = 1; price[
'PEN:CUR'] = 3.675148; price[
'PGK:CUR'] = 3.595313; price[
'PHP:CUR'] = 56.400499; price[
'PKR:CUR'] = 285.356887; price[
'PLN:CUR'] = 4.224316; price[
'PYG:CUR'] = 7214.978573; price[
'QAR:CUR'] = 3.6463; price[
'RON:CUR'] = 4.6376; price[
'RSD:CUR'] = 109.564184; price[
'RUB:CUR'] = 80.485009; price[
'RWF:CUR'] = 1126.585001; price[
'SAR:CUR'] = 3.750456; price[
'SBD:CUR'] = 8.333912; price[
'SCR:CUR'] = 13.143215; price[
'SDG:CUR'] = 600.5; price[
'SEK:CUR'] = 10.850145; price[
'SGD:CUR'] = 1.35331; price[
'SHP:CUR'] = 0.808004; price[
'SLL:CUR'] = 17665; price[
'SOS:CUR'] = 568.519064; price[
'SRD:CUR'] = 37.3; price[
'SSP:CUR'] = 130.26; price[
'STD:CUR'] = 22823.990504; price[
'STN:CUR'] = 22.867383; price[
'SVC:CUR'] = 8.751208; price[
'SYP:CUR'] = 2512.53; price[
'SZL:CUR'] = 19.680225; price[
'THB:CUR'] = 34.8045; price[
'TJS:CUR'] = 10.936116; price[
'TMT:CUR'] = 3.5; price[
'TND:CUR'] = 3.097; price[
'TOP:CUR'] = 2.3797; price[
'TRY:CUR'] = 20.3411; price[
'TTD:CUR'] = 6.791146; price[
'TWD:CUR'] = 30.602358; price[
'TZS:CUR'] = 2365; price[
'UAH:CUR'] = 36.755244; price[
'UGX:CUR'] = 3739.83257; price[
'USD:CUR'] = 1; price[
'UYU:CUR'] = 38.849072; price[
'UZS:CUR'] = 11420.955684; price[
'VES:CUR'] = 26.096899; price[
'VND:CUR'] = 23490; price[
'VUV:CUR'] = 118.979; price[
'WST:CUR'] = 2.72551; price[
'XAF:CUR'] = 612.788118; price[
'XAG:CUR'] = 0.04313041; price[
'XAU:CUR'] = 0.00051408; price[
'XCD:CUR'] = 2.70255; price[
'XDR:CUR'] = 0.75108; price[
'XOF:CUR'] = 612.788118; price[
'XPD:CUR'] = 0.0007005; price[
'XPF:CUR'] = 111.478456; price[
'XPT:CUR'] = 0.00096707; price[
'YER:CUR'] = 250.349961; price[
'ZAR:CUR'] = 19.720229; price[
'ZMW:CUR'] = 19.352611; price[
'ZWL:CUR'] = 322
;price['BEF:CUR'] = 36.6663;
price['NLG:CUR'] = 2.00303;
price['UDI:CUR'] = 3.75067;
price['ATS:CUR'] = 12.5072;
price['PTE:CUR'] = 182.225;
price['ESP:CUR'] = 151.234;
price['CYP:CUR'] = 0.53195;
price['EEK:CUR'] = 14.2217;
price['FIM:CUR'] = 5.40428;
price['GRD:CUR'] = 309.719;
price['LUF:CUR'] = 36.6663;
price['MTL:CUR'] = 0.390205833577212;
price['PTE:CUR'] = 182.225;
price['SKK:CUR'] = 27.3825;
price['TRL:CUR'] = 3029245;
price['DEM:CUR'] = 0.58227;
price['ITL:CUR'] = 1759.941;
price['VEB:CUR'] = 7126358185;
price['ZWD:CUR'] = 61182767543;
price['ADP:CUR'] = 0.16;
price['FRF:CUR'] = 888;
price['BYR:CUR'] = 0.4677;
price['ECS:CUR'] = 0;
price['SDR:CUR'] = 1.39;
price['IEP:CUR'] = 888;
price['LVL:CUR'] = 888;
price['SIT:CUR'] = 888;
price['ZMK:CUR'] = 888;
price['LTL:CUR'] = 2.8345;
price['TMM:CUR'] = 17499.93;
price['IEP:CUR'] = 0.88518;
price['RUB:CUR'] = 75.88426;
price['VEF:CUR'] = 9888888888;

显示效果:汇率换算器

 

参考文章:http://www.theicstock.com/gonglve/1021.html

百分比在线计算器

根号计算器

5色环电阻阻值在线计算器

快递单号查询

人民币大小写在线转换

体积单位换算器

posted @ 2023-05-30 18:01  kaiser099  阅读(255)  评论(0编辑  收藏  举报