0

I am using Autodesk Infraworks software and have to set some tips using both javascript and html.

I use a set of table where there is a field called USER_SUM_ALL. It stores different numbers like 10, 20, 20.3, 20.8 etc.

The problem is that that program shows number not like in original but with 15 digits after comma. 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

What can be done here to display numbers properly?

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. Right now it doesn't react to field outside HTML tags.

Pavel Pereverzev
  • 459
  • 1
  • 6
  • 21
  • Possible duplicate of [How to deal with floating point number precision in JavaScript?](https://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript) – SzybkiSasza Oct 12 '18 at 09:51
  • what is the backend language you are using here, as you are mentioning table. – somsgod Oct 12 '18 at 09:52
  • @somsgod looks like HTML – Pavel Pereverzev Oct 12 '18 at 09:54
  • toFixed(1); in javascript will do the work later you can check more for if number is in int dont fix after decimal places. – somsgod Oct 12 '18 at 09:59
  • @somsgod yes, I used this method however it just rewrites the initial data which is read incorrectly by HTML – Pavel Pereverzev Oct 12 '18 at 10:06
  • can you post more code here that will help to understand better. – somsgod Oct 12 '18 at 10:08
  • @somsgod just edited – Pavel Pereverzev Oct 12 '18 at 13:04
  • can you provide this to what the value of this %USER_SUM_ALL% you are getting and what outcome you need from test function. – somsgod Oct 13 '18 at 07:38
  • @somsgod %USER_SUM_ALL% is taken from a layer imported in Infraworks. In this software you can make tooltips using both HTML and Javascript. When cursor placed on object a tooltip appeare where you can see some value from attribute table of layer. For example, you need to see the area of building, so you mak an html expression like `Number is :%USER_SUM_PL_ALL%` where there is a reference to a specific field between percent signs. – Pavel Pereverzev Oct 15 '18 at 06:17

1 Answers1

1

Using javascript you can select size of numbers after dot(.) example number.toFixed(2) returns 2 number after dot.

Shyqa
  • 46
  • 6
  • I used it in another tab of Infraworks' settings. In table it stores and looks correctly. But when I make a request via HTML using `%USER_SUM_ALL%` statement it gives digits despite the fact that they are not exist. – Pavel Pereverzev Oct 12 '18 at 09:57