Swaps Swaps - 1 month ago 5x
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)


Sure you can:

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