简体   繁体   English

浮点数显示错误

[英]Wrong display of float number

I am using Autodesk Infraworks software and have to set some tips using both javascript and html. 我正在使用Autodesk Infraworks软件,必须同时使用javascript和html设置一些提示。

I use a set of table where there is a field called USER_SUM_ALL. 我使用一组表,其中有一个名为USER_SUM_ALL的字段。 It stores different numbers like 10, 20, 20.3, 20.8 etc. 它存储不同的数字,例如10、20、20.3、20.8等。

The problem is that that program shows number not like in original but with 15 digits after comma. 问题在于该程序显示的数字与原始数字不同,但用逗号后的15位数字表示。 This is a code: 这是一个代码:

<div><b><font size="5"> TEST: %USER_SUM_ALL% </font></b></div>

And it shows not 20.8 but 20.800000000000001 它显示的不是20.8而是20.800000000000001

What can be done here to display numbers properly? 在这里可以做什么以正确显示数字?

Upd. UPD。

<script>
function test(){
    var x = %USER_SUM_ALL%;
    document.write(x);
};

</script>


<div><b><font size="5"> Number is: <script> test() </script> </font></b></div>

Here my goal is to show the number in field USER_SUM_ALL . 在这里,我的目标是在USER_SUM_ALL字段中显示数字。 Right now it doesn't react to field outside HTML tags. 目前,它对HTML标记之外的字段没有反应。

使用javascript,您可以选择点号(。)示例后的数字大小。number.toFixed(2)返回点号后的2个数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM