1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
<?xml version="1.0" encoding="UTF-8"?>
<helpdocument version="1.0">
<!--
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<meta>
<topic id="textscalcguidenumbers_textxml" indexer="include" status="PUBLISH">
<title xml-lang="en-US" id="tit">Converting Text to Numbers</title>
<filename>/text/scalc/guide/numbers_text.xhp</filename>
</topic>
</meta>
<body>
<bookmark xml-lang="en-US" branch="index" id="bm_id3145068">
<bookmark_value>formats; text as numbers</bookmark_value>
<bookmark_value>time format conversion</bookmark_value>
<bookmark_value>date formats;conversion</bookmark_value>
<bookmark_value>converting;text, into numbers</bookmark_value>
</bookmark>
<h1 id="hd_id0908200901265171"><variable id="numbers_text"><link href="text/scalc/guide/numbers_text.xhp" name="Converting Text to Numbers">Converting Text to Numbers</link></variable></h1>
<section id="text">
<paragraph xml-lang="en-US" id="par_id0908200901265127" role="paragraph">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.</paragraph>
<paragraph xml-lang="en-US" id="par_id0908200901265196" role="paragraph"><emph>Only integer numbers including exponent are converted</emph>, 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.</paragraph>
<paragraph xml-lang="en-US" id="par_id0908200901265220" role="paragraph">The following ISO 8601 formats are converted:</paragraph>
<list type="unordered">
<listitem>
<paragraph xml-lang="en-US" id="par_id0908200901265288" role="paragraph">CCYY-MM-DD</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_id0908200901265267" role="paragraph">CCYY-MM-DDThh:mm</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_id0908200901265248" role="paragraph">CCYY-MM-DDThh:mm:ss</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_id0908200901265374" role="paragraph">CCYY-MM-DDThh:mm:ss,s</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_id0908200901265327" role="paragraph">CCYY-MM-DDThh:mm:ss.s</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_id0908200901265399" role="paragraph">hh:mm</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_id0908200901265347" role="paragraph">hh:mm:ss</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_id0908200901265349" role="paragraph">hh:mm:ss,s</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_id0908200901265342" role="paragraph">hh:mm:ss.s</paragraph>
</listitem>
</list>
<paragraph xml-lang="en-US" id="par_id0908200901265491" role="paragraph">The century code CC may not be omitted. Instead of the T date and time separator, exactly one space character may be used.</paragraph>
<paragraph xml-lang="en-US" id="par_id0908200901265467" role="paragraph">If a date is given, it must be a valid Gregorian calendar date. In this case the optional time must be in the range 00:00 to 23:59:59.99999...</paragraph>
<paragraph xml-lang="en-US" id="par_id0908200901265420" role="paragraph">If only a time string is given, it may have an hours value of more than 24, while minutes and seconds can have a maximum value of 59.</paragraph>
<note id="par_id761567607207916">The conversion is done for single scalar values only, not within ranges.</note>
<paragraph xml-lang="en-US" id="par_id0908200901265448" role="paragraph">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.</paragraph>
<paragraph xml-lang="en-US" id="par_id090820090126540" role="paragraph">Strings inside formulas are also converted, such as in ="1999-11-22"+42, which returns the date 42 days after November 22nd, 1999. Calculations involving localized dates as strings inside the formula return an error. For example, the localized date string "11/22/1999" or "22.11.1999" cannot be used for the automatic conversion.</paragraph>
<embed href="text/shared/00/00000001.xhp#regexnumex"/>
<h2 id="hd_id1005200903485368">Example</h2>
<paragraph xml-lang="en-US" id="par_id1005200903485359" role="paragraph">In A1 enter the text <literal>'1e2</literal> (which is converted to the number 100 internally).</paragraph>
<paragraph xml-lang="en-US" id="par_id1005200903485341" role="paragraph">In A2 enter <literal>=A1+1</literal> (which correctly results in 101).</paragraph>
<paragraph role="paragraph" id="par_id891567607263849">The formula <literal>=SUM(A1:A2)</literal>, 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.</paragraph>
<paragraph role="paragraph" id="par_id611567607779380"><literal>=SUM("1E2";1)</literal> returns #VALUE! because SUM() and some others that iterate over number sequences explicitly check the argument type.</paragraph>
</section>
<h2 id="hd_id871567772424915">Changing the default text to number conversion settings</h2>
<paragraph role="paragraph" id="par_id111567772433803">The text to number conversion can be customized in the <link href="text/shared/optionen/detailedcalculation.xhp" name="detailed_link">Detailed Calculation Settings</link> option.</paragraph>
<section id="relatedtopics">
<embed href="text/shared/optionen/detailedcalculation.xhp#detailed_heading"/>
<embed href="text/scalc/guide/text_numbers.xhp#text_numbers"/>
<embed href="text/scalc/guide/integer_leading_zero.xhp#integer_leading_zero"/>
<paragraph xml-lang="en-US" id="par_id0908200901265544" role="paragraph"><link href="text/shared/01/05020300.xhp" name="Format - Cells - Numbers">Format - Cells - Numbers</link></paragraph>
<embed href="text/scalc/guide/format_value.xhp#format_value"/>
</section>
</body>
</helpdocument>
|