Hi everyone,
As you all know i'm knew to Sketchup ruby and i can't find this anywhere online.
I have a variable that has a float number and i wanted to round it.
Var = 1.8854523497846
Desired answer Var = 1.9
Also if i can recommend any online sources for Sketchup ruby I’ll be thankful
Thanks
Rounding
6 posts
• Page 1 of 1
Re: RoundingHi,
Caution: this will create a constant (not very suitable for a variable)
is better ![]()
SU uses Ruby 1.8.6 and .round(x) is new in Ruby 1.9. You'll have to wait for SU9 or code it yourself, or like this:
![]() See http://www.ruby-doc.org/core/ and select the 'Float' class. For online SketchUp-Ruby docs, see: http://forums.sketchucation.com/viewtopic.php?f=180&t=10142 (well done Dan !) Hope this helps, Didier Bur
Ecole Nationale Supérieure d'Architecture de Nancy (F) Re: Rounding@morci429: In reality.. there is no such think as "Sketchup Ruby." There is only Ruby, that that gets loaded by the Sketchup application, and then loads special Google API modules and classes, that extend Ruby so we can work with SKP models.
You need to learn Standard Ruby.. first. And you must have the Reference for the Standard Ruby Modules and Classes.
Yes, you poined to the current Ruby 1.9.x core. I have links to the online 1.8.6 and 1.8.7 Core Refs, as well as downloadable offline CHM Refs in this post: RUBY PROGRAMMING REFERENCES
Re: RoundingHow about:
OR for a singleton Mixin method, save as 'mixin/float_round_to.rb' (make a subfolder under plugins called 'mixin' and put the file there.):
then use it by extending your variable: require('mixin/float_round_to.rb') var.extend(Mixin::Round_to) var1 = var.round_to(1) >> 1.9 var3 = var.round_to(3) >> 1.885 var8=var.round_to(8) >> 1.88545235
Re: RoundingIf you want to round it as output [as astring] then you can use
var_string = sprintf("%.1f", var) for 1 dp etc TIG
6 posts
• Page 1 of 1
|
Who is online
Users browsing this forum: Jorgen10 and 7 guests