Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
#
include
<
QLocale
>
5
6
void
wrapInFunction
()
7
{
8
{
9
//! [0]
10
QLocale egyptian(QLocale::Arabic, QLocale::Egypt);
11
QString s1 = egyptian.toString(1.571429E+07,
'e'
);
12
QString s2 = egyptian.toString(10);
13
14
double
d = egyptian.toDouble(s1);
15
int
i = egyptian.toInt(s2);
16
//! [0]
17
}
18
19
{
20
//! [1]
21
bool
ok;
22
double
d;
23
24
QLocale::setDefault(QLocale::C);
// uses '.' as a decimal point
25
QLocale cLocale;
// default-constructed C locale
26
d = cLocale.toDouble(
"1234,56"
, &ok);
// ok == false, d == 0
27
d = cLocale.toDouble(
"1234.56"
, &ok);
// ok == true, d == 1234.56
28
29
QLocale::setDefault(QLocale::German);
// uses ',' as a decimal point
30
QLocale german;
// default-constructed German locale
31
d = german.toDouble(
"1234,56"
, &ok);
// ok == true, d == 1234.56
32
d = german.toDouble(
"1234.56"
, &ok);
// ok == false, d == 0
33
34
QLocale::setDefault(QLocale::English);
35
// Default locale now uses ',' as a group separator.
36
QString str = QString(
"%1 %L2 %L3"
).arg(12345).arg(12345).arg(12345, 0, 16);
37
// str == "12345 12,345 3039"
38
//! [1]
39
}
40
41
{
42
//! [2]
43
QLocale korean(
"ko"
);
44
QLocale swiss(
"de_CH"
);
45
//! [2]
46
}
47
48
{
49
//! [3]
50
bool
ok;
51
double
d;
52
53
QLocale c(QLocale::C);
54
d = c.toDouble(
"1234.56"
, &ok);
// ok == true, d == 1234.56
55
d = c.toDouble(
"1,234.56"
, &ok);
// ok == true, d == 1234.56
56
d = c.toDouble(
"1234,56"
, &ok);
// ok == false, d == 0
57
58
QLocale german(QLocale::German);
59
d = german.toDouble(
"1234,56"
, &ok);
// ok == true, d == 1234.56
60
d = german.toDouble(
"1.234,56"
, &ok);
// ok == true, d == 1234.56
61
d = german.toDouble(
"1234.56"
, &ok);
// ok == false, d == 0
62
63
d = german.toDouble(
"1.234"
, &ok);
// ok == true, d == 1234.0
64
//! [3]
65
}
66
67
{
68
//! [3-qstringview]
69
bool
ok;
70
double
d;
71
72
QLocale c(QLocale::C);
73
d = c.toDouble(u"1234.56", &ok);
// ok == true, d == 1234.56
74
d = c.toDouble(u"1,234.56", &ok);
// ok == true, d == 1234.56
75
d = c.toDouble(u"1234,56", &ok);
// ok == false, d == 0
76
77
QLocale german(QLocale::German);
78
d = german.toDouble(u"1234,56", &ok);
// ok == true, d == 1234.56
79
d = german.toDouble(u"1.234,56", &ok);
// ok == true, d == 1234.56
80
d = german.toDouble(u"1234.56", &ok);
// ok == false, d == 0
81
82
d = german.toDouble(u"1.234", &ok);
// ok == true, d == 1234.0
83
//! [3-qstringview]
84
}
85
}
wrapInFunction
void wrapInFunction()
[16]
Definition
src_corelib_io_qdatastream.cpp:6
qtbase
src
corelib
doc
snippets
code
src_corelib_text_qlocale.cpp
Generated on
for Qt by
1.18.0