forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 2
Ruby Numbers Operations
Quincy Larson edited this page Aug 20, 2016
·
1 revision
In Ruby you can perform all standard math operations on numbers, including: addition +
, subtraction -
, multiplication *
, division /
, find remainders %
, and work with exponents **
.
- Numbers can be added together using the
+
operator.
15 + 25
# returns:
40
- Numbers can be subtracted from one another using the
-
operator.
25 - 15
# returns:
10
- Numbers can be multiplied together using the
*
operator.
10 * 5
# returns:
50
- Numbers can be divided by one another using the
/
operator.
10 / 5
# returns:
2
- Remainders can be found using the modulus
%
operator.
10 % 3
# returns:
1 # because the remainder of 10/3 is 1
- Exponents can be calculated using the
**
operator.
2 ** 3
# returns:
8 # because 2 to the third power, or 2 * 2 * 2 = 8
Home | Next |
---|---|
Ruby Numbers Basics | Ruby Numbers Methods |
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links