當前位置:首頁 » 網頁前端 » 匯率轉換web代碼
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

匯率轉換web代碼

發布時間: 2022-06-16 03:35:21

㈠ 怎麼做一個實時匯率轉換的php程序

代碼很簡單,通過CURL調用google的API。
當然,得把PHP的CURL模塊打開
function Currency($from_Currency,$to_Currency,$amount) {
$amount = urlencode($amount);
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);
$url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Currency";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$rawdata = curl_exec($ch);
curl_close($ch);
$data = explode('"', $rawdata);
$data = explode(' ', $data['3']);
$var = $data['0'];
return round($var,2);
}
echo Currency("RMB","HKD",100);

㈡ Excel中VBA代碼匯率轉換的格式問題

等到你第二次再執行這段代碼的時候,
Target.NumberFormatLocal 的屬性值為代碼設置的 "[$€-2] #,##0.00_);[紅色]([$€-2] #,##0.00)",最左面第一個字元為「[」,即不是 「€」,也不是「$」,當然不會執行 IF 塊內的代碼嘍!

顯示肯定是以歐元打頭的值了!

㈢ 求python代碼。貨幣轉換人民幣對美元。格式為: 人民幣:20 美元:xxx

#獲取實時匯率,根據匯率換算

import requests

import re

import json

url='https://sp0..com/8aQDcjqpAAV3otqbppnN2DJv/api.php? query=1%E7%BE%8E%E5%85%83%E7%AD%89%E4%BA%8E%E5%A4%9A%E5%B0%91%E4%BA%BA%E6%B0%91%E5%B8%81&co=&resource_id=6017&t=1560336236210&cardId=6017&ie=utf8&oe=gbk&cb=op_aladdin_callback&format=json&tn=&cb=jQuery110201293669134906772_1560336178301&_=1560336178313'

res=requests.get(url)

res.coding='gbk'

changge=res.text

changge=re.findall('{.*}',changge)

changge=json.loads(changge[0])

changge=changge['data'][0]['content2']

n=re.findall('1人民幣元=(.*)美元',changge)

n=float(n[0])

usd=rnb/n

print('人民幣:{0} 美元:{1}'.format(rnb,round(usd,2)))

㈣ php里實現匯率轉換

簡單的一個方法:
在載入網頁時預讀所有貨幣的匯率,並存為JS數組
當下拉列表更改選擇時,用JS控制顯示匯率,並計算貨幣價格

這個思路,你參考一下,應該是非常簡單的

㈤ 用vb編寫 人民幣匯率

保存下面的代碼到一個後綴名為FRM的文件中,再用VB打開即可。
============
VERSION
5.00
Begin
VB.Form
Form1
Caption
=
"人民幣轉換工具"
ClientHeight
=
3195
ClientLeft
=
60
ClientTop
=
345
ClientWidth
=
4680
LinkTopic
=
"Form1"
ScaleHeight
=
3195
ScaleWidth
=
4680
StartUpPosition
=
3
'窗口預設
Begin
VB.OptionButton
Option1
Caption
=
"轉換成歐元"
Height
=
495
Index
=
3
Left
=
1680
TabIndex
=
4
Top
=
1200
Width
=
1335
End
Begin
VB.OptionButton
Option1
Caption
=
"轉換成日元"
Height
=
495
Index
=
2
Left
=
240
TabIndex
=
3
Top
=
1200
Width
=
1215
End
Begin
VB.OptionButton
Option1
Caption
=
$"Form2.frx":0000
Height
=
495
Index
=
1
Left
=
1680
TabIndex
=
2
Top
=
720
Width
=
1335
End
Begin
VB.OptionButton
Option1
Caption
=
"轉換成美元"
Height
=
495
Index
=
0
Left
=
240
TabIndex
=
1
Top
=
720
Width
=
1215
End
Begin
VB.TextBox
Text1
Height
=
375
Left
=
240
TabIndex
=
0
Top
=
120
Width
=
1455
End
Begin
VB.Label
Label1
Height
=
375
Left
=
480
TabIndex
=
5
Top
=
1800
Width
=
3015
End
End
Attribute
VB_Name
=
"Form1"
Attribute
VB_GlobalNameSpace
=
False
Attribute
VB_Creatable
=
False
Attribute
VB_PredeclaredId
=
True
Attribute
VB_Exposed
=
False
Option
Explicit
Private
Sub
Option1_Click(Index
As
Integer)
Dim
t
As
Single
t
=
Val(Text1.Text)
Label1.Caption
=
FormatNumber(Choose(Index
+
1,
t
/
7.7,
t
/
15.47,
t
/
0.081,
t
/
10.8),
,
vbTrue)
End
Sub

㈥ python這個匯率轉換程序怎麼編寫

可以參考代碼:

def test(n):

if n[-1]=="R":

return str(int(n[0:-1])/6.5)+"D"

elif n[-1]=="D":

return str(int(n[0:-1])*6.5)+"R"

或是可以使用input獲取鍵盤輸入的字元,而不是作為方法的傳入參數n