diff options
author | Mike <git@mjpa.co.uk> | 2011-02-15 01:15:43 +0300 |
---|---|---|
committer | Mike <git@mjpa.co.uk> | 2011-02-15 01:15:43 +0300 |
commit | 32006237089adc3e1a2a1359e2ae8e2d9bb96686 (patch) | |
tree | e9d611c87a3274605fe3a03d2552bd9a42b24d64 /src | |
parent | baead82c03ce4cc5744da58c55e0cd22ada12ce7 (diff) |
Fixes for handling very precise decimal numbers
Diffstat (limited to 'src')
-rw-r--r-- | src/JSON.cpp | 5 | ||||
-rw-r--r-- | src/JSON.h | 2 | ||||
-rw-r--r-- | src/JSONValue.cpp | 12 |
3 files changed, 10 insertions, 9 deletions
diff --git a/src/JSON.cpp b/src/JSON.cpp index 1718874..a79a477 100644 --- a/src/JSON.cpp +++ b/src/JSON.cpp @@ -255,10 +255,11 @@ bool JSON::ExtractString(const wchar_t **data, std::wstring &str) * * @return int Returns the int value of the number found */ -int JSON::ParseInt(const wchar_t **data) +double JSON::ParseInt(const wchar_t **data) { - int integer = 0; + double integer = 0; while (**data != 0 && **data >= '0' && **data <= '9') integer = integer * 10 + (*(*data)++ - '0'); + return integer; } @@ -78,7 +78,7 @@ class JSON protected: static bool SkipWhitespace(const wchar_t **data); static bool ExtractString(const wchar_t **data, std::wstring &str); - static int ParseInt(const wchar_t **data); + static double ParseInt(const wchar_t **data); private: JSON(); }; diff --git a/src/JSONValue.cpp b/src/JSONValue.cpp index 48db420..be8e0bc 100644 --- a/src/JSONValue.cpp +++ b/src/JSONValue.cpp @@ -86,7 +86,7 @@ JSONValue *JSONValue::Parse(const wchar_t **data) if (**data == L'0') (*data)++; else if (**data >= L'1' && **data <= L'9') - number = (double)JSON::ParseInt(data); + number = JSON::ParseInt(data); else return NULL; @@ -100,8 +100,8 @@ JSONValue *JSONValue::Parse(const wchar_t **data) return NULL; // Find the decimal and sort the decimal place out - double decimal = (double)JSON::ParseInt(data); - while((int)decimal > 0) decimal /= 10.0f; + double decimal = JSON::ParseInt(data); + while(decimal > 1.0) decimal /= 10.0; // Save the number number += decimal; @@ -125,9 +125,9 @@ JSONValue *JSONValue::Parse(const wchar_t **data) return NULL; // Sort the expo out - int expo = JSON::ParseInt(data); - for (int i = 0; i < expo; i++) - number = neg_expo ? (number / 10.0) : (number * 10); + double expo = JSON::ParseInt(data); + for (double i = 0.0; i < expo; i++) + number = neg_expo ? (number / 10.0) : (number * 10.0); } // Was it neg? |