Swaps Swaps -4 years ago 118
Ruby Question

Ruby self assign float variable with methods like .round()

I have come across a very common scenario as follows-

var_float += 1234.1234
var_float = var_float.round(2)

Here the value for
is getting calculated with some complicated expressions and there I cannot do like
var_float += 1234.1234.round(2)
this. Hence one more line to reassign the same.

I was wondering if there's any better way to do this ruby?
For ex. if I can do something like
var_float .= round(2)

Answer Source

Sure you can:

var_float = (var_float+1234.1234).round(2)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download