diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2016-08-19 10:13:45 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2016-08-23 13:46:22 +0000 |
commit | 8b7dbfe1e0c0d4b8d0984fb381f1a0bb6b566e76 (patch) | |
tree | 3438c6ec351cc6cadbbacdfd170affd8605e6a44 /tests | |
parent | 4f0988c3907406087dbfdc193abfbf767678d814 (diff) |
V4: Correctly format on Number.toPrecision(n)
The ecmascript standard mandates that we add trailing zeroes if the
given precision is greater than the number of digits available. The
only way to request this from QLocale is currently QString::asprintf(),
which adds a few other incompatibilities that are easier to 'fix' by
editing the resulting string. Thus we use it as a stop gap measure
until we can expose better API from qtbase.
Task-number: QTBUG-55358
Change-Id: Iafc11f21abb341fbe458ad75b46b4222ae5bc1db
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qjsengine/tst_qjsengine.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index b1d19b5796..0001a22103 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -2003,6 +2003,15 @@ void tst_QJSEngine::jsNumberClass() QJSValue ret = eng.evaluate("new Number(123).toPrecision()"); QVERIFY(ret.isString()); QCOMPARE(ret.toString(), QString::fromLatin1("123")); + ret = eng.evaluate("new Number(42).toPrecision(1)"); + QVERIFY(ret.isString()); + QCOMPARE(ret.toString(), QString::fromLatin1("4e+1")); + ret = eng.evaluate("new Number(42).toPrecision(2)"); + QVERIFY(ret.isString()); + QCOMPARE(ret.toString(), QString::fromLatin1("42")); + ret = eng.evaluate("new Number(42).toPrecision(3)"); + QVERIFY(ret.isString()); + QCOMPARE(ret.toString(), QString::fromLatin1("42.0")); } } |