aboutsummaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp
blob: 6fedb1f67bf1e36d67c27aa7dc773ee957545dc2 (plain)
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
//! [0]
egyptian = QLocale(QLocale.Arabic, QLocale.Egypt)
s1 = egyptian.toString(1.571429E+07, 'e')
s2 = egyptian.toString(10)

(d, ok) = egyptian.toDouble(s1)
(i, ok) = egyptian.toInt(s2)
//! [0]


//! [1]
QLocale.setDefault(QLocale(QLocale.Hebrew, QLocale.Israel))
hebrew = QLocale() # Constructs a default QLocale
s1 = hebrew.toString(15714.3, 'e')

QLocale.setDefault(QLocale(QLocale.C))
(d, ok) = QString("1234,56").toDouble()   # ok == false
(d, ok) = QString("1234.56").toDouble()   # ok == true, d == 1234.56

QLocale.setDefault(QLocale(QLocale.German))
(d, ok) = QString("1234,56").toDouble()   # ok == true, d == 1234.56
(d, ok) = QString("1234.56").toDouble()   # ok == true, d == 1234.56

QLocale.setDefault(QLocale(QLocale.English, QLocale.UnitedStates))
string = QString("%1 %L2 %L3").arg(12345).arg(12345).arg(12345, 0, 16)
# string == "12345 12,345 3039"
//! [1]


//! [2]
korean = QLocale("ko")
swiss = QLocale("de_CH")
//! [2]


//! [3]
c = QLocale(QLocale.C)
(d, ok) = c.toDouble( "1234.56" )  # ok == true, d == 1234.56
(d, ok) = c.toDouble( "1,234.56" ) # ok == true, d == 1234.56
(d, ok) = c.toDouble( "1234,56" )  # ok == false

german = QLocale(QLocale.German)
(d, ok) = german.toDouble( "1234,56" )  # ok == true, d == 1234.56
(d, ok) = german.toDouble( "1.234,56" ) # ok == true, d == 1234.56
(d, ok) = german.toDouble( "1234.56" )  # ok == false

(d, ok) = german.toDouble( "1.234" )    # ok == true, d == 1234.0
//! [3]