Add all values from an array together?

I've been picking apart a piece of code for a few hours now, can't seem to get this quite right.

* I have an array full of floats in a variable

* I would like to take that array and add all values in the array together, and spit that out into another variable

Example Array data: [0.55, 0.25]

What I want from that: 1 variable: 0.80

The array can grow/shrink and I have no way of knowing how big it is at the time of calculation.

Thanks in advance!
arr = [1,2,3,4]


p arr.inject(0.0) {|r, val| r+= val}
works perfectly, except I needed to do "p = "

thanks!

(mod can close)
Actually that `p` is just to print out the result.
oh. well, I mangled it up so I could store it in a variable 🙂

Thanks, Tsuki!
This one works also

arr = [1,2,3,4]arr.inject🙂+)Looks more elegantMore stuff

http://stackoverflow.com/questions/1538789/how-to-sum-array-members-in-ruby
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/add-all-values-from-an-array-together.20790/