diff options
| Commit | 83a4f8032fbdad2ea35ef101dfb14433f672b6d9 (patch) | |
|---|---|---|
| Author | 2022-05-29 13:04:41 +0300 | |
| Committer | 2022-05-29 13:04:41 +0300 | |
| Files | f8858bef657e9d9006db986ed38a385ef601ac39 /src | |
| FMI-OOP-P2_Tables-83a4f8032fbdad2ea35ef101dfb14433f672b6d9.tar FMI-OOP-P2_Tables-83a4f8032fbdad2ea35ef101dfb14433f672b6d9.tar.gz FMI-OOP-P2_Tables-83a4f8032fbdad2ea35ef101dfb14433f672b6d9.zip | ||
| Parent | f788177bd2b63ea92872ce49bee5d9975227ccad (diff) | |
Autocommit at 29.05.2022 @ 13:04
2 files changed, 3 insertions, 14 deletions
| -rw-r--r-- | src/Generic/String/String.cpp | 14 | ||||
| -rw-r--r-- | src/Models/Table.cpp | 3 |
diff --git a/src/Generic/String/String.cpp b/src/Generic/String/String.cpp index d37e9b7..d9cc235 100644 --- a/src/Generic/String/String.cpp +++ b/src/Generic/String/String.cpp @@ -81,18 +81,8 @@ String& String::operator+=(unsigned number) { * Converts the number to a C-style string and then uses += to append it. */ String& String::operator+=(double number) { - unsigned tempLen = 0; - for (unsigned tmp = number; tmp > 0 || tempLen == 0; tmp /= 10) - tempLen++; - - char* tmp = new char[tempLen + 1]; - tmp[tempLen] = '\0'; - for (unsigned i = tempLen - 1; i < tempLen; i--, number /= 10) - tmp[i] = number % 10 + '0'; - - *this += tmp; - delete[] tmp; - return *this; + if (number < 0) *this += "-"; + return ((*this += (unsigned)number) += ".") += (unsigned)((number - (unsigned)number) * DOUBLE_PRECISION); } String::String() : String("") {} diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp index 66edef4..afb77b1 100644 --- a/src/Models/Table.cpp +++ b/src/Models/Table.cpp @@ -30,10 +30,9 @@ void Table::putCell(unsigned row, unsigned col, const char* rawValue) { Cell* newCell; if (containsNumber(rawValue)) { - double intParse = atoi(rawValue); double doubleParse = atof(rawValue); - newCell = (abs(doubleParse) - abs(intParse) > 0.00001) + newCell = (abs(doubleParse) - (unsigned)(abs(doubleParse)) > 0.00001) ? (Cell*)new CellDouble(doubleParse) : (Cell*)new CellInt(intParse); } else { |
