aboutsummaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp')
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp
new file mode 100644
index 000000000..6fedb1f67
--- /dev/null
+++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_tools_qlocale.cpp
@@ -0,0 +1,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]