Ruby: Change negative number to positive number?

Shpigford picture Shpigford · Mar 19, 2010 · Viewed 65.9k times · Source

What's the simplest way of changing a negative number to positive with ruby?

ie. Change "-300" to "300"

Answer

Yacoby picture Yacoby · Mar 19, 2010

Using abs will return the absolute value of a number

-300.abs  # 300
300.abs   # 300