💡 LightUp 7.1 | SketchUp's only real-time renderer that uses object-based rendering
Download Trial
Ruby Numeric. Help - Sorry for bothering. RESOLVED
-
I have to display some values, and most of all are integers, but some will be float. This is why I must use float.
I want to get rid of zero to that values that don't require it.
This is what I want:%(#4000BF)[3.3 => 3.3
4.8 => 4.8]
16.0 => 16I could do the trick in many ways but I'm still looking for something native.
There is no native way, but I find this on web:
#extend the Float class class Float def to_i_if if self - floor == 0 floor else self end end end
But here will be a problem: if I have a number like this: 4.00001, won't be converted to integer. For that, the method to_i_if can be enhanced:
class Float def to_i_if(threshold=0) if self - floor <= threshold floor else self end end end
treshold => display format like this: 0.01 (how many zeroes you need)
I found this on web and I thought to share it.
Advertisement