Kevin McAllister Posted August 17, 2016 Share Posted August 17, 2016 (edited) Can someone help with rounding numbers and setting the number of decimal places for Marionette output? I'm using the Round node set to zero and when I start with 150.5 as a layer elevation I get 150.000000 as a result back. Not sure what I'm doing wrong. Kevin Edited August 17, 2016 by Kevin McAllister Quote Link to comment
Marionette Maven Marissa Farrell Posted August 17, 2016 Marionette Maven Share Posted August 17, 2016 (edited) Hey Kevin, So rounding doesn't appear to truncate the number, which is what you're really looking for. If you use the "trunc" node after your "round" node, I think you'll get what you want. I'm also in the process of getting nodes to follow the rounding display preferences set in the application, but that won't be available for a bit longer. EDIT: Trunc may only solve the issue if you're looking for whole numbers. Edited August 17, 2016 by MarissaF Quote Link to comment
Marionette Maven Marissa Farrell Posted August 17, 2016 Marionette Maven Share Posted August 17, 2016 (edited) Also - to follow up. Since the reason for your rounding is display purposes, another way to get rid of trailing zeros would be to use the "String" node (str) in the String category. This would be useful for the cases where you may want to round out 3 decimal places but still see what's past the whole number. After you convert the number to a string, you can put it right back into the text object. Edited August 17, 2016 by MarissaF Quote Link to comment
Kevin McAllister Posted August 17, 2016 Author Share Posted August 17, 2016 (edited) Hi Marissa, Thanks for the info. I'll look at Trunc. I accidentally posted an old image with my original post. Here's a clearer example of what's happening. The Layer elevation is set to 150.5mm. The top object contains the Round node, which doesn't round or truncate. The bottom node is without it showing the value it should be acting on. The Round node is the first node I've encountered that only contains Python script. It doesn't call the Vectorscript rounding function. I looked online for some documentation and Round seems to be correct. I found this documentation that talks about getting weird results from a "Float" - https://docs.python.org/3/library/functions.html#round Perhaps its something with the output of the Get Layer Elevation node output? I don't know what a "Float" is.... Kevin Edited August 17, 2016 by Kevin McAllister Quote Link to comment
Marionette Maven Marissa Farrell Posted August 17, 2016 Marionette Maven Share Posted August 17, 2016 A float is a variable type. You could compare it to a double. Since Python is an interpreted language, it generally chooses the type of our variables on its own. In actuality, I believe ALL of our Math nodes use only Python. This is for development reasons, Vectorscript isn't really being maintained anymore since Python is much more flexible. The reason the number of decimal places is so long is because VW uses long floats in its math. This becomes more apparent when displaying values from a script. Since VW has the preference of how far out numbers are displayed, many users aren't aware how precise the values used in the software actually are. In my post right above your most recent one is my best solution so far. The Str node will get rid of trailing zeros, so after you pick your precision with the Round node, it's done the best at displaying what you want (except in the case of an Integer, then you would want to use Trunc). This will also change the variable type, though, from float to string, so I would advise doing any math you want done BEFORE converting it. You're more than welcome to use the VS Round function, but it is unlikely we will ever ship it with default content since it's getting outdated. Quote Link to comment
Marionette Maven Marissa Farrell Posted August 17, 2016 Marionette Maven Share Posted August 17, 2016 (edited) I also want to clarify what you're seeing with python's Round function. https://docs.python.org/2/library/functions.html#round Note: The behavior of round() for floats can be surprising: for example, round(2.675, 2) gives 2.67 instead of the expected 2.68. This is not a bug: it’s a result of the fact that most decimal fractions can’t be represented exactly as a float. See Floating Point Arithmetic: Issues and Limitations for more information. http://stackoverflow.com/questions/7515266/rounding-problem-with-python The documentation for the built-in round() function says that it rounds to the nearest value, rounding ties away from zero. Since the decimal fraction 2.675 is exactly halfway between 2.67 and 2.68, you might expect the result here to be (a binary approximation to) 2.68. It’s not, because when the decimal string 2.675 is converted to a binary floating-point number, it’s again replaced with a binary approximation, whose exact value is 2.67499999999999982236431605997495353221893310546875 Since this approximation is slightly closer to 2.67 than to 2.68, it’s rounded down. Edited August 17, 2016 by MarissaF Quote Link to comment
Kevin McAllister Posted August 17, 2016 Author Share Posted August 17, 2016 Thanks for all of the info. I can get what I need from this. One last question - is there a way to convert a node's output from a float to something that will round properly? After some experimenting it seems rounding is required before converting to a string. I can find a node that converts to a Float, but nothing that converts from a Float to a real number for example. (I suppose this may all be solved when you finish updating the nodes so the follow the rounding display precision....) Kevin Quote Link to comment
Marionette Maven Marissa Farrell Posted August 17, 2016 Marionette Maven Share Posted August 17, 2016 I haven't found anything browsing the internet that can do that. Python appears to only have 4 numeric types - int, float, long, and complex - unfortunately it doesn't look like any of them would play nicer with round. Quote Link to comment
Kevin McAllister Posted August 17, 2016 Author Share Posted August 17, 2016 Ok. Interesting. This explains why I couldn't get things to Round properly in Alan's fence network. I ended up using Ceil and Floor instead. This makes your project to make the nodes follow the rounding display precision even more important... except how are you going to round things to the correct precision :-) Kevin Quote Link to comment
AlanW Posted August 18, 2016 Share Posted August 18, 2016 (edited) Kevin, this one rounds the numbers Hans-Olav set this up, Marissa added the add thousands and sub-string and I added the text formatting. Just move the object between the design layer in the OIP and the note changes Also the rounding node rounds up and down by the <> 0.5 of the result in the file attached. Hope I am not missing the point again? HTH Level_Marker.vwx Rounding_001.vwx Edited October 29, 2018 by Marissa Farrell Attached files Quote Link to comment
Kevin McAllister Posted August 18, 2016 Author Share Posted August 18, 2016 (edited) Thanks Alan. Your prodding made me go back at look at things again and I tracked down the cause. It turns out the problem is my Concat node. Not sure why. Even though its getting a rounded number as input and its only supposed to combine strings, it somehow adds back the extra zeros. It may be a limitation of the VS Concat command. I really wish we could use the Debug mode to trace things within a Marionette object..... And that selecting the Node dropdown menu automatically switched back out of the Debug mode.... Kevin Edited August 18, 2016 by Kevin McAllister Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.