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]
5
QLocale
egyptian
(
QLocale
::
Arabic
,
QLocale
::
Egypt
);
6
QString
s1
= egyptian.toString(1.571429E+07,
'e'
);
7
QString
s2
= egyptian.toString(10);
8
9
double
d
= egyptian.toDouble(s1);
10
int
i
= egyptian.toInt(s2);
11
//! [0]
12
13
14
//! [1]
15
bool
ok
;
16
double
d
;
17
18
QLocale::setDefault(QLocale::C);
// uses '.' as a decimal point
19
QLocale
cLocale
;
// default-constructed C locale
20
d
= cLocale.toDouble(
"1234,56"
, &ok);
// ok == false, d == 0
21
d
= cLocale.toDouble(
"1234.56"
, &ok);
// ok == true, d == 1234.56
22
23
QLocale::setDefault(QLocale::German);
// uses ',' as a decimal point
24
QLocale
german
;
// default-constructed German locale
25
d
= german.toDouble(
"1234,56"
, &ok);
// ok == true, d == 1234.56
26
d
= german.toDouble(
"1234.56"
, &ok);
// ok == false, d == 0
27
28
QLocale::setDefault(QLocale::English);
29
// Default locale now uses ',' as a group separator.
30
QString
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]
36
QLocale
korean
(
"ko"
);
37
QLocale
swiss
(
"de_CH"
);
38
//! [2]
39
40
41
//! [3]
42
bool
ok
;
43
double
d
;
44
45
QLocale
c
(
QLocale
::
C
);
46
d
= c.toDouble(
"1234.56"
, &ok);
// ok == true, d == 1234.56
47
d
= c.toDouble(
"1,234.56"
, &ok);
// ok == true, d == 1234.56
48
d
= c.toDouble(
"1234,56"
, &ok);
// ok == false, d == 0
49
50
QLocale
german
(
QLocale
::
German
);
51
d
= german.toDouble(
"1234,56"
, &ok);
// ok == true, d == 1234.56
52
d
= german.toDouble(
"1.234,56"
, &ok);
// ok == true, d == 1234.56
53
d
= german.toDouble(
"1234.56"
, &ok);
// ok == false, d == 0
54
55
d
= german.toDouble(
"1.234"
, &ok);
// ok == true, d == 1234.0
56
//! [3]
57
58
//! [3-qstringview]
59
bool
ok
;
60
double
d
;
61
62
QLocale
c
(
QLocale
::
C
);
63
d
= c.toDouble(u"1234.56", &ok);
// ok == true, d == 1234.56
64
d
= c.toDouble(u"1,234.56", &ok);
// ok == true, d == 1234.56
65
d
= c.toDouble(u"1234,56", &ok);
// ok == false, d == 0
66
67
QLocale
german
(
QLocale
::
German
);
68
d
= german.toDouble(u"1234,56", &ok);
// ok == true, d == 1234.56
69
d
= german.toDouble(u"1.234,56", &ok);
// ok == true, d == 1234.56
70
d
= german.toDouble(u"1234.56", &ok);
// ok == false, d == 0
71
72
d
= german.toDouble(u"1.234", &ok);
// ok == true, d == 1234.0
73
//! [3-qstringview]
i
auto i
Definition
doc_src_qset.cpp:70
str
QString str
[3]
Definition
src_corelib_io_qtextstream.cpp:50
ok
bool ok
[2]
Definition
src_corelib_text_qbytearrayview.cpp:17
s1
QString s1
Definition
src_corelib_text_qlocale.cpp:6
s2
QString s2
Definition
src_corelib_text_qlocale.cpp:7
german
QLocale german(QLocale::German)
cLocale
QLocale cLocale
Definition
src_corelib_text_qlocale.cpp:19
german
QLocale german
Definition
src_corelib_text_qlocale.cpp:24
d
double d
[1]
Definition
src_corelib_text_qlocale.cpp:9
c
QLocale c(QLocale::C)
egyptian
QLocale egyptian(QLocale::Arabic, QLocale::Egypt)
[0]
swiss
QLocale swiss("de_CH")
korean
QLocale korean("ko")
[1]
qtbase
src
corelib
doc
snippets
code
src_corelib_text_qlocale.cpp
Generated on Thu Nov 14 2024 00:38:53 for Qt by
1.12.0