㈠ 怎么做一个实时汇率转换的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