Shpigford Shpigford - 2 years ago 112
Ruby Question

Ruby: Change negative number to positive number?

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

ie. Change "-300" to "300"

Answer Source

Using abs will return the absolute value of a number

-300.abs  # 300
300.abs   # 300
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download