# 变量

### 声明变量

使用等号 `=` 声明一个变量。

```
discount = 10%                         | 10%
cost = $550                            | $550
cost - discount                        | $495.00  
```

变量可以是一个单词，也可以是一个完整的短语。

### 全局变量

要声明在所有工作表上都有效的变量，请转到 `Settings > Calculator > Global Variables`，然后点击加号按钮添加新变量。

### 重新定义变量

可以通过给变量赋予新值来重新定义它。

最近定义的值将在后续行中使用。

```
monthly rent = $1,900 // 2018      | $1,900
monthly rent = $2,150 // 2019      | $2,150   
monthly rent / 4 people            | $537.50
```

#### 变量可以被累加和减去

使用 `+=` 和 `-=` 运算符来修改变量的值

![](/files/mPHpWPBcF8lOTAjYGFGR)

## 使用变量的技巧

#### 查看变量的值

在 Mac 上，按住 Shift 键并悬停在变量上，即可查看其值。

<figure><img src="/files/j0wTLjKMVZ7pqQBboF5m" alt="" width="158"><figcaption><p>在 Mac 上查看变量值</p></figcaption></figure>

在 iPad 和 iPhone 上，选择一个变量即可查看其值。

<figure><img src="/files/WfLOzUcAov5RVOmAaB67" alt="" width="359"><figcaption><p>在 iPad 和 iPhone 上查看变量值</p></figcaption></figure>

#### 自动补全变量名

与其输入一个很长的变量名，不如按 **escape** 键，然后按 **return** 键，即可快速插入完整的变量名。

![按 escape 键自动补全长变量名](/files/EDuvbTs6x07MoFjXcHra)

### 重命名变量

当您重命名变量时，Soulver 会提供自动更新所有引用该变量的行的选项，以使用新名称。

要调用此功能，只需将光标移动到另一行，并在变量声明行的变量名称进行编辑即可。

<div align="left"><figure><img src="/files/lhAS1HZ9phofb4YgOSMQ" alt="" width="372"><figcaption></figcaption></figure></div>

## 关于变量声明需要注意的事项

#### 变量在使用前必须声明

您不能在变量被声明**之前**引用它。

此行为与编程语言中变量的工作方式一致（但与 Soulver 2 不同）。

#### 货币四舍五入不适用于变量声明行

当您以货币形式声明变量时，它将显示**不进行四舍五入**，这样可以明确变量中存储的实际值。

在后续行中使用时，货币四舍五入会像往常一样应用。

<figure><img src="/files/6NZtu34hdBv4XLn4kx6f" alt="" width="563"><figcaption><p>可以清楚地知道“每日成本”的实际值</p></figcaption></figure>

#### 变量声明可以排除在浮动总计之外

使用 “View > Total options” 菜单配置浮动总计是否应包含或排除变量声明行。

<figure><img src="/files/J3CfsfEeFiUgzdSeQcPF" alt="" width="563"><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.soulver.app/zh/documentation/variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
