Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
6QString s1 = egyptian.toString(1.571429E+07, 'e');
8
9double d = egyptian.toDouble(s1);
12
13
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
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"
33
34
37QLocale swiss("de_CH");
39
40
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
57
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
double toDouble(const QString &s, bool *ok=nullptr) const
Returns the double represented by the localized string s.
Definition qlocale.h:969
static void setDefault(const QLocale &locale)
\nonreentrant
Definition qlocale.cpp:1295
@ Egypt
Definition qlocale.h:639
int toInt(const QString &s, bool *ok=nullptr) const
Returns the int represented by the localized string s.
Definition qlocale.h:955
QString toString(qlonglong i) const
Returns a localized string representation of i.
Definition qlocale.cpp:2052
@ Arabic
Definition qlocale.h:58
@ German
Definition qlocale.h:138
@ English
Definition qlocale.h:119
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
Definition qstring.cpp:8870
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
const GLubyte * c
QLocale egyptian(QLocale::Arabic, QLocale::Egypt)
[0]
QLocale cLocale
QLocale swiss("de_CH")
QLocale german
QLocale c(QLocale::C)
QLocale korean("ko")
[1]