freeCodeCamp/guide/chinese/ruby/ruby-numbers-operations/index.md

29 lines
828 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Ruby Numbers Operations
localeTitle: Ruby Numbers操作
---
在Ruby中您可以对数字执行所有标准数学运算包括加`+` ,减法`-` ,乘法`*` ,除法`/` ,查找余数`%` ,以及使用指数`**` 。
## 加成:
* 可以使用`+`运算符将数字相加。 `ruby 15 + 25 #=> 40`
## 减法:
* 可以使用`-`运算符将数字相互减去。 `ruby 25 - 15 #=> 10`
## 乘法:
* 可以使用`*`运算符将数字相乘。 `ruby 10 * 5 #=> 50`
## 师:
* 可以使用`/`运算符将数字相互分开。 `ruby 10 / 5 #=> 2`
## 余:
* 可以使用模数`%`运算符找到剩余。 `ruby 10 % 3 #=> 1 # because the remainder of 10/3 is 1`
## 指数:
* 可以使用`**`运算符计算指数。 `ruby 2 ** 3 #=> 8 # because 2 to the third power, or 2 * 2 * 2 = 8`