Grasshopper

algorithmic modeling for Rhino

I tried the search for help removing the scientific notation format of numbers. I found this:

But when I try it, I get this:


Any ideas what am I doing wrong?


Thanks,


Gustavo

Views: 5662

Replies to This Discussion

You need to supply a formatting pattern:

Format("{0:?}", x)

The question mark needs to be replaced by the formatting tag or pattern you're looking for. For example:

Round to two decimal places:
Format("{0:0.00}", x)

Display two decimal places, allow for four decimal places:
Format("{0:0.00##}", x)

Make sure the number->string formatting is lossless:
Format("{0:R}", x)

Format using scientific notation:
Format("{0:E}", x)

Format using percentage notation:
Format("{0:P}", x)

Format using hexadecimal notation:
Format("{0:X}", x)


and so on and so forth.

--
David Rutten
david@mcneel.com
Seattle, WA
Thanks for the extra info here David, very useful. That was not the problem however. I figured out what's up.

Take a look:


Is this the intended functionality or a bug?
Ah, of course. When you feed a number though a Text panel, it becomes text. So you were formatting a String instead of a number.

--
David Rutten
david@mcneel.com
Seattle, WA
got it! sorry for wasting your time :)
I see this sometimes, too. I think it would be great if the panel would output the original data type, not its string representation.

- Giulio
_______________
giulio@mcneel.com
McNeel Europe, Barcelona

Any idea what's wrong here? (thought i shouldn't make a new thread just about this one) Thanks!

You sure you need the double quotes and the comma x to be included in the result? Sounds like you're only after {0:R}.

Or is the question about the orange number parameter?

Hey, David, thanks for taking the time to answer! I't probably something banal, but I still don't get it..

The Format() function in the expression language takes a string (ie. text) and then a collection of values. The string describes where to insert the values, and how to insert them. For example, let's assume we want to format two numbers, one integer and a floating point value. The integer represents an index and it should appear inside square brackets, then we want the floating point number rounded to a maximum of 4 decimal places (but always using at least one decimal place, even if it's zero), and then, in parentheses a scientific notation representation using 8 decimal digits of the number.

So, assuming the index is 16 and the value is 47.280006208, what we are after is:

[16] 47.28 (4.72800062E+001)

To make this work, we need a formatting pattern that looks like:

[{0}] {1:0.0###}    ({1:E8})

The square brackets, spaces and parenthesis are just part of the output, they have no meaning whilst formatting. Everything inside the curly brackets though will be replaced with a specific formatting of one of the values.

When using the Format component as shown above, the formatting pattern is just text data. The component knows that it is supposed to use the Format() function using the pattern text and whatever additional data is provided.

When you invoke the Format() method in an expression, you do need to make sure that the pattern is actually text:

So here the pattern needs to be encased in double quotes, otherwise it will be treated as code, rather than text.

You cannot use the formatting method in the internal expression of a number parameter, because this method returns text, whereas the number parameter is only capable of storing numbers. Any expression that you put into a number parameter had better return numbers as a result.

Thank You for the detailed answer! I figured out why it wast working.. The information was already string because that is what the karamba component outputs. Is there any solution to transform string scientific notation to "normal" notation?
Also, R doesn't see to work like i understood it should (as in showing the number in normal notation, no matter how long)

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service