diff options
| Commit | d2cdb5796067925ef58cba9e38976792b26a2fc5 (patch) | |
|---|---|---|
| Author | 2022-05-29 13:09:42 +0300 | |
| Committer | 2022-05-29 13:09:42 +0300 | |
| Files | 2c1643360235055ff0f41a744c6c72c3e9965a8b /src | |
| FMI-OOP-P2_Tables-d2cdb5796067925ef58cba9e38976792b26a2fc5.tar FMI-OOP-P2_Tables-d2cdb5796067925ef58cba9e38976792b26a2fc5.tar.gz FMI-OOP-P2_Tables-d2cdb5796067925ef58cba9e38976792b26a2fc5.zip | ||
| Parent | 83a4f8032fbdad2ea35ef101dfb14433f672b6d9 (diff) | |
Autocommit at 29.05.2022 @ 13:09
3 files changed, 22 insertions, 4 deletions
| -rw-r--r-- | src/Generic/String/String.cpp | 19 | ||||
| -rw-r--r-- | src/Generic/String/String.h | 2 | ||||
| -rw-r--r-- | src/Models/Table.cpp | 5 |
diff --git a/src/Generic/String/String.cpp b/src/Generic/String/String.cpp index d9cc235..ed096e8 100644 --- a/src/Generic/String/String.cpp +++ b/src/Generic/String/String.cpp @@ -62,6 +62,17 @@ String& String::operator+=(const char* str) { /*! * Converts the number to a C-style string and then uses += to append it. */ +String& String::operator+=(int number) { + if (number < 0) { + *this += "-"; + number *= -1; + } + return *this += (unsigned)number; +} + +/*! + * Converts the number to a C-style string and then uses += to append it. + */ String& String::operator+=(unsigned number) { unsigned tempLen = 0; for (unsigned tmp = number; tmp > 0 || tempLen == 0; tmp /= 10) @@ -81,8 +92,12 @@ String& String::operator+=(unsigned number) { * Converts the number to a C-style string and then uses += to append it. */ String& String::operator+=(double number) { - if (number < 0) *this += "-"; - return ((*this += (unsigned)number) += ".") += (unsigned)((number - (unsigned)number) * DOUBLE_PRECISION); + if (number < 0) { + *this += "-"; + number *= -1; + } + return ((*this += (unsigned)number) += ".") + += (unsigned)((number - (unsigned)number) * DOUBLE_PRECISION); } String::String() : String("") {} diff --git a/src/Generic/String/String.h b/src/Generic/String/String.h index f30151a..c520bc9 100644 --- a/src/Generic/String/String.h +++ b/src/Generic/String/String.h @@ -32,6 +32,8 @@ public: //! Appends a C-style string String& operator+=(const char* str); //! Appends a number + String& operator+=(int number); + //! Appends a number String& operator+=(unsigned number); //! Appends a number String& operator+=(double number); diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp index afb77b1..132559f 100644 --- a/src/Models/Table.cpp +++ b/src/Models/Table.cpp @@ -31,9 +31,10 @@ void Table::putCell(unsigned row, unsigned col, const char* rawValue) { if (containsNumber(rawValue)) { double doubleParse = atof(rawValue); + unsigned intPart = abs(doubleParse); - newCell = (abs(doubleParse) - (unsigned)(abs(doubleParse)) > 0.00001) - ? (Cell*)new CellDouble(doubleParse) : (Cell*)new CellInt(intParse); + newCell = (abs(doubleParse) - intPart > 0.00001) + ? (Cell*)new CellDouble(doubleParse) : (Cell*)new CellInt(intPart); } else { newCell = (*rawValue == '=') |
