]> Shamusworld >> Repos - architektonas/blob - src/base/rs_utility.cpp
Fixed thumbnail rendering in LibraryWidget and DXF detection.
[architektonas] / src / base / rs_utility.cpp
1 // rs_utility.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  05/05/2010  Moved implementation from header to this file. :-)
15 //
16
17 #include "rs_utility.h"
18
19 /**
20  * Converts a double to a string cutting away unnecessary 0's.
21  * e.g. 2.70000  -> 2.7
22  */
23 QString RS_Utility::doubleToString(double value, int precision/*= 6*/)
24 {
25         QString ret;
26
27         ret.setNum(value, 'f', precision);
28
29         if (ret.contains('.'))
30         {
31                 // remove trailing zeros:
32                 while (ret.at(ret.length() - 1) == '0')
33                 {
34                         ret.truncate(ret.length() - 1);
35                 }
36
37                 // remove trailing .
38                 if (ret.at(ret.length() - 1) == '.')
39                 {
40                         ret.truncate(ret.length() - 1);
41                 }
42         }
43
44         return ret;
45 }