javascript - 尝试将 xml 节点值中的小数四舍五入为两位数

标签 javascript xml

我想删除小数并只打印前两个小数值,我该怎么做。

xml

<bookstore>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>2.21595037861026842</price>
</bookstore>

如何仅打印价格标签中的前 2 位小数值

x=xmlDoc.getElementsByTagName("price")[0].childNodes[0];
document.write(x.nodeValue);

结果:2.21

最佳答案

x = xmlDoc.getElementsByTagName("price")[0].childNodes[0];
var z = x.nodeValue;
var y = Math.round(z * 100) / 100;
document.write(y);

关于javascript - 尝试将 xml 节点值中的小数四舍五入为两位数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29769592/

相关文章:

java - listView 不会从底部填充

javascript - 更改 mapbox 中的 Maki 图标颜色?

Javascript 连接 2 个数组

JavaScript继承: How can we inherit object and function where object is created from function using new operator and has prototype functions

javascript - Highcharts 数据标签重叠列

java - 如何将xml转换为java字符串列表

python - 使用 html5lib 将任何 HTML 解析为 XML

java - 为什么我的 fragment 是空白的?

java - 如何在没有 DOMException 的情况下使用 DOM importNode

javascript - 在 Javascript 中将带空格的字符串数组转换为小写,然后在 Webkit 中搜索失败