目录

# 将文本转换为数字

Defaults settings in Calc converts text inside cells to the respective numeric values if an unambiguous conversion is possible. If no conversion is possible, Calc returns a #VALUE! error.

Only integer numbers including exponent are converted, and ISO 8601 dates and times in their extended formats with separators. Anything else, like fractional numbers with decimal separators or dates other than ISO 8601, is not converted, as the text string would be locale dependent. Leading and trailing blanks are ignored.

以下 ISO 8601 格式会被转换:

- CCYY-MM-DD

- CCYY-MM-DDThh:mm

- CCYY-MM-DDThh:mm:ss

- CCYY-MM-DDThh:mm:ss,s

- CCYY-MM-DDThh:mm:ss.s

- hh:mm

- hh:mm:ss

- hh:mm:ss,s

- hh:mm:ss.s

世纪代码 CC 可能不会省略。而日期与时间的分隔符 T 可能会只用一个空格字符来代替。

如果给定的是日期，则该日期必须为有效的公历日期。在这种情况下，可选的时间范围为 00:00 到 23:59:59.99999...

如果仅给定时间字符串，则该字符串的小时值可以大于 24，而分钟和秒钟的最大值为 59。

The conversion is done for single scalar values only, not within ranges.

The conversion is done for single scalar values, as in =A1+A2, or ="1E2"+1. Cell range arguments are not affected, so SUM(A1:A2) differs from A1+A2 if at least one of the two cells contain a convertible string.

公式中的字符串也会被转换，例如，="1999-11-22"+42 会返回 1999 年 11 月 22 日后的第 42 天的日期。如果将已本地化的日期作为公式中的字符串进行计算，则会返回一个错误。例如，已本地化的日期字符串 "11/22/1999" 或 "22.11.1999" 无法用于自动转换。

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".

## 示例

In A1 enter the text '1e2 (which is converted to the number 100 internally).

In A2 enter =A1+1 (which correctly results in 101).

The formula =SUM(A1:A2), returns 101 instead of 201 because the conversion does not occur in a range, only for single scalar values. Here, '1e2 is treated as string which is ignored for the SUM function.

=SUM("1E2";1) returns #VALUE! because SUM() and some others that iterate over number sequences explicitly check the argument type.

## Changing the default text to number conversion settings

The text to number conversion can be customized in the Detailed Calculation Settings option.

相关主题

Detailed Calculation Settings

将数字格式化为文本

输入带前置零的数字

格式 - 单元格 - 数字

格式化带小数的数字

请支持我们!