Commit 174eae5bedb96c7f102e5ea4ef3d84c49c17c5ec
1 parent
dce20eb2
Exists in
master
Adicionado método de converter double para QString sem notação científica.
Showing
3 changed files
with
19 additions
and
0 deletions
Show diff stats
cacic-teste/testcacic.cpp
@@ -243,6 +243,15 @@ void CTestCacic::testColetaSoftware() | @@ -243,6 +243,15 @@ void CTestCacic::testColetaSoftware() | ||
243 | QVERIFY(!OCacicSoftware.toJsonObject().empty()); | 243 | QVERIFY(!OCacicSoftware.toJsonObject().empty()); |
244 | } | 244 | } |
245 | 245 | ||
246 | +void CTestCacic::testConvertDouble() | ||
247 | +{ | ||
248 | + double number = 4.0905; | ||
249 | + | ||
250 | + QString converted = OCacic.convertDouble(number); | ||
251 | + | ||
252 | + QVERIFY(converted.toDouble() == number); | ||
253 | +} | ||
254 | + | ||
246 | void CTestCacic::cleanupTestCase() | 255 | void CTestCacic::cleanupTestCase() |
247 | { | 256 | { |
248 | OCacic.deleteFile("configRequest.json"); | 257 | OCacic.deleteFile("configRequest.json"); |
cacic-teste/testcacic.h
@@ -70,6 +70,7 @@ private slots: | @@ -70,6 +70,7 @@ private slots: | ||
70 | void testRemoveRegistry(); | 70 | void testRemoveRegistry(); |
71 | void testIniciarDaemon(); | 71 | void testIniciarDaemon(); |
72 | void testColetaSoftware(); | 72 | void testColetaSoftware(); |
73 | + void testConvertDouble(); | ||
73 | void cleanupTestCase(); | 74 | void cleanupTestCase(); |
74 | }; | 75 | }; |
75 | 76 |
src/ccacic.cpp
@@ -286,6 +286,15 @@ void CCacic::setChaveCrypt(const QString &value) | @@ -286,6 +286,15 @@ void CCacic::setChaveCrypt(const QString &value) | ||
286 | chaveCrypt = value; | 286 | chaveCrypt = value; |
287 | } | 287 | } |
288 | 288 | ||
289 | +QString CCacic::convertDouble(const double &number, const int &precision) | ||
290 | +{ | ||
291 | + std::ostringstream ss; | ||
292 | + ss.precision(precision); | ||
293 | + ss << std::fixed << number; | ||
294 | + | ||
295 | + qDebug() << QString::fromStdString(ss.str()); | ||
296 | + return QString::fromStdString(ss.str()); | ||
297 | +} | ||
289 | 298 | ||
290 | /*Getters/Setters | 299 | /*Getters/Setters |
291 | * End. | 300 | * End. |