package main
import (
"fmt"
"strconv"
)
func main() {
k := 10/3.0
i := fmt.Sprintf("%.2f", k)
f,_ := strconv.ParseFloat(i, 2)
fmt.Println(f)
}
Run Code Online (Sandbox Code Playgroud)
我必须编写上面的程序,以将go float64变量的精度降低到2.在这种情况下,我使用了strconv和fmt.是否有其他逻辑方法可以完成?
我正在使用带有 express 的 node.js。我正在尝试设置基本服务器,但不知道为什么会收到响应错误。
var http = require('http');
var myServer = http.createServer(function(req,res){
response.writeHead(200, {"Content-Type" : "text/plain"});
response.write('Hello World');
response.end();
});
myServer.listen(3000);
Run Code Online (Sandbox Code Playgroud) 我有一个XML文件,我想将其转换/导出为csv(类似)格式.
例:
<root>
<child>
<Name>John</Name>
<Surname>Doe</Surname>
<Name>George</Name>
<Surname>Washington</Surname>
</child>
</root>
Run Code Online (Sandbox Code Playgroud)
ATM我是这样做的(打印用于调试,还没有完成):
#!/bin/python env
import xml.etree.ElementTree as etree
tree = etree.parse('./foobar.xml')
root = tree.getroot()
elements = ('Name', 'Surname')
for i in elements:
for i in root.iter(i):
print(i.text)
Run Code Online (Sandbox Code Playgroud)
电流输出:
John
George
Doe
Washington
Run Code Online (Sandbox Code Playgroud)
结果我想得到:
John, Doe
George, Washington
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我一把吗?
非常感谢你.