我想删除小数并只打印前两个小数值,我该怎么做。
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/