Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_corelib_text_qlocale.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4//! [0]
6QString s1 = egyptian.toString(1.571429E+07, 'e');
7QString s2 = egyptian.toString(10);
8
9double d = egyptian.toDouble(s1);
10int i = egyptian.toInt(s2);
11//! [0]
12
13
14//! [1]
15bool ok;
16double d;
17
18QLocale::setDefault(QLocale::C); // uses '.' as a decimal point
19QLocale cLocale; // default-constructed C locale
20d = cLocale.toDouble("1234,56", &ok); // ok == false, d == 0
21d = cLocale.toDouble("1234.56", &ok); // ok == true, d == 1234.56
22
23QLocale::setDefault(QLocale::German); // uses ',' as a decimal point
24QLocale german; // default-constructed German locale
25d = german.toDouble("1234,56", &ok); // ok == true, d == 1234.56
26d = german.toDouble("1234.56", &ok); // ok == false, d == 0
27
28QLocale::setDefault(QLocale::English);
29// Default locale now uses ',' as a group separator.
30QString str = QString("%1 %L2 %L3").arg(12345).arg(12345).arg(12345, 0, 16);
31// str == "12345 12,345 3039"
32//! [1]
33
34
35//! [2]
37QLocale swiss("de_CH");
38//! [2]
39
40
41//! [3]
42bool ok;
43double d;
44
46d = c.toDouble("1234.56", &ok); // ok == true, d == 1234.56
47d = c.toDouble("1,234.56", &ok); // ok == true, d == 1234.56
48d = c.toDouble("1234,56", &ok); // ok == false, d == 0
49
51d = german.toDouble("1234,56", &ok); // ok == true, d == 1234.56
52d = german.toDouble("1.234,56", &ok); // ok == true, d == 1234.56
53d = german.toDouble("1234.56", &ok); // ok == false, d == 0
54
55d = german.toDouble("1.234", &ok); // ok == true, d == 1234.0
56//! [3]
57
58//! [3-qstringview]
59bool ok;
60double d;
61
63d = c.toDouble(u"1234.56", &ok); // ok == true, d == 1234.56
64d = c.toDouble(u"1,234.56", &ok); // ok == true, d == 1234.56
65d = c.toDouble(u"1234,56", &ok); // ok == false, d == 0
66
68d = german.toDouble(u"1234,56", &ok); // ok == true, d == 1234.56
69d = german.toDouble(u"1.234,56", &ok); // ok == true, d == 1234.56
70d = german.toDouble(u"1234.56", &ok); // ok == false, d == 0
71
72d = german.toDouble(u"1.234", &ok); // ok == true, d == 1234.0
73//! [3-qstringview]
auto i
QString str
[3]
QLocale german(QLocale::German)
QLocale cLocale
QLocale german
double d
[1]
QLocale c(QLocale::C)
QLocale egyptian(QLocale::Arabic, QLocale::Egypt)
[0]
QLocale swiss("de_CH")
QLocale korean("ko")
[1]