如何将小数长度降低到空手道框架中最多两个小数位
下面的功能是返回输出为8.1100000000001。我只想输出最多两个小数点。即)8.11
- [2.16,1.34,1.32,1.25,0.65,0.48,48,0.42,42,0.26,0.26,0.14,06,0.06,03,0
- def array =
- ] '结果'); karate.set('result',temp + x)}
- bacarate.foreach(数组,有趣)
- 打印结果
Below function is returning the output is 8.110000000000001. I want the output only upto two decimal places. i.e) 8.11
- def array = [2.16,1.34,1.32,1.25,0.65,0.48,0.42,0.26,0.14,0.06,0.03,0]
- def result = 0
- def fun = function(x){ var temp = karate.get('result'); karate.set('result', temp + x )}
- karate.forEach(array, fun)
- print result
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是使用JS
Math.Round()
的一种方法。但这可能有一些局限性。只需编写一个函数即可进行一次转换并使用它。请注意,您可以使用 java Interop 如果您想使用
bigdecimal
等。在网上找到大量解决方案。This is one way, using the JS
Math.round()
.But it may have some limitations. Just write a function to do the conversion once and use it. Note that you can use Java interop if you want to make use of
BigDecimal
etc. You can find plenty of solutions on the net.