Hello everyone!
I have a set of models in Infraworks and for some objects I have to make tooltips. There is a layer with is a field containing float numbers called USER_SUM_ALL. It stores different numbers like 10.0, 20.0, 20.3, 20.8 etc.
The problem is that that program shows number not like in original but with 15 digits after comma. Here 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?
Hello everyone!
I have a set of models in Infraworks and for some objects I have to make tooltips. There is a layer with is a field containing float numbers called USER_SUM_ALL. It stores different numbers like 10.0, 20.0, 20.3, 20.8 etc.
The problem is that that program shows number not like in original but with 15 digits after comma. Here 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?
Looks like I deal with it by myself.
Anyway, if somebody face with this issue, probably my solution would be helpful. However it doesn't seem to be 100% right.
So, as far as I know rigth now, some programming languages has problems with displaying float numbers. Here is an article about it. There is probably no way to limit digits after comma in HTML editor in Infraworks, it grabs values onlyt from datasource table. Whatever you have in a field with real (double, float) number data, Infraworks will display the integer number plus point and 15 digits after it. Exceptions are numbers that have only a zero after point. But, as I wrote in question, numbers like 20.3 will be shown like 20.300000000000001.
Recently I observred javascript guide for Infraworks and found method similar to arcpy.da.UpdateCursor from ArcGIS (I'm still user of this software) there. And for objects which numbers I want to be show correctly, wrote a script that creates a substitute of a tooltip. It works for certain selected objects in a model but can be edited to update all needed data.
Here it goes:
var db = app.ActiveModelDb; var classID = db.TableIndex("USER_BUILDINGS"); //reference to a datasource var table = db.Table(classID); var sset = app.ActiveSelectionSet; //taking only selected object var filter = sset.GetFilter(db.TableIndex("USER_BUILDINGS")); table.StartQuery(filter); table.BeginWriteBatch(); var read; var write = table.GetWriteRow(); while (read = table.Next()) { //loop through selected objects var sq = read.USER_SUM_ALL; //getting float number write.TAG = "<div><b><font size='5'>SQUARE is " + sq.toFixed(1).toString(); //limit digits and comvert into a string table.UpdateFeature(write, read.ID); //updating feature } table.EndQuery();
After that the tooltip for layer should be just
%TAG%
As a result the original data will be displayed in tooltip.
Looks like I deal with it by myself.
Anyway, if somebody face with this issue, probably my solution would be helpful. However it doesn't seem to be 100% right.
So, as far as I know rigth now, some programming languages has problems with displaying float numbers. Here is an article about it. There is probably no way to limit digits after comma in HTML editor in Infraworks, it grabs values onlyt from datasource table. Whatever you have in a field with real (double, float) number data, Infraworks will display the integer number plus point and 15 digits after it. Exceptions are numbers that have only a zero after point. But, as I wrote in question, numbers like 20.3 will be shown like 20.300000000000001.
Recently I observred javascript guide for Infraworks and found method similar to arcpy.da.UpdateCursor from ArcGIS (I'm still user of this software) there. And for objects which numbers I want to be show correctly, wrote a script that creates a substitute of a tooltip. It works for certain selected objects in a model but can be edited to update all needed data.
Here it goes:
var db = app.ActiveModelDb; var classID = db.TableIndex("USER_BUILDINGS"); //reference to a datasource var table = db.Table(classID); var sset = app.ActiveSelectionSet; //taking only selected object var filter = sset.GetFilter(db.TableIndex("USER_BUILDINGS")); table.StartQuery(filter); table.BeginWriteBatch(); var read; var write = table.GetWriteRow(); while (read = table.Next()) { //loop through selected objects var sq = read.USER_SUM_ALL; //getting float number write.TAG = "<div><b><font size='5'>SQUARE is " + sq.toFixed(1).toString(); //limit digits and comvert into a string table.UpdateFeature(write, read.ID); //updating feature } table.EndQuery();
After that the tooltip for layer should be just
%TAG%
As a result the original data will be displayed in tooltip.
Can't find what you're looking for? Ask the community or share your knowledge.