Fixed bug in asDouble but changed its operation. Decimal only.
This commit is contained in:
1 parent
75df8d0282
commit
974a509767
2 files changed
+53
-2
No files matched your search
+50
-2
@@ -1,4 +1,3 @@
|
||||
|
||||
#include "ZString.h"
|
||||
#include "Log.h"
|
||||
#include "Exception.h"
|
||||
@@ -125,7 +124,56 @@ namespace coreutils {
|
||||
}
|
||||
|
||||
double ZString::asDouble() {
|
||||
return strtod(cursor, &cursor);
|
||||
double value = 0;
|
||||
bool negative = false;
|
||||
char *end = data + length;
|
||||
if(*cursor == '-') {
|
||||
negative = true;
|
||||
++cursor;
|
||||
} else if(*cursor == '+')
|
||||
++cursor;
|
||||
if(cursor == end)
|
||||
return 0;
|
||||
while((*cursor >= '0') && (*cursor <= '9')) {
|
||||
value *= 10;
|
||||
value += *cursor - 48;
|
||||
++cursor;
|
||||
if(cursor == end) {
|
||||
if(negative)
|
||||
return -value;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
}
|
||||
if(*cursor != '.')
|
||||
if(cursor == end) {
|
||||
if(negative)
|
||||
return -value;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
++cursor;
|
||||
if(cursor == end) {
|
||||
if(negative)
|
||||
return -value;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
double div = 10;
|
||||
while((*cursor >= '0') && (*cursor <= '9')) {
|
||||
value += (*cursor - 48) / div;
|
||||
div *= 10;
|
||||
++cursor;
|
||||
if(cursor == end) {
|
||||
if(negative)
|
||||
return -value;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
}
|
||||
if(negative)
|
||||
return -value;
|
||||
return value;
|
||||
}
|
||||
|
||||
int ZString::incrementCursor(int length) {
|
||||
|
||||
Reference in new issue
Block a user