Is there a way to round Length with SU max precision?

Hi all,

I would like to “round” a Length and output it as a float in inch but with the max precision that a user can setup (0.000000") and not only the selected one.

For exemple :
If I do this : 0.999998.to_l.to_s.to_l.to_f, I would return 0.999998 in all cases and not 1.0 if the model have an other precision than 0.000000.

Or, the sub question is How SketchUp rounds Lengths ?

Thanks for your help :wink:

You can check this classes:

For example Length#to_s-instance_method format a length as a String using the current units formatting settings for the model. (So if the user’s model is set to feet, this method will return a nicely formatted length in feet.)

You can also query the actual precision and use e.g. like:

prec = Sketchup.active_model.options["UnitsOptions"]["LengthPrecision"]
myvar = my_float.round(prec)
1 Like

myvar = my_float.round(prec)

This is exactly what I search for. Thanks !

1 Like

The last part of the post were lost due to bad connection, but you get it … :wink:

You also need to refer to Ruby Core documentation …

Also see the module method: Sketchup.format_length()