diff options
author | Musab Kılıç <musabkilic@protonmail.com> | 2021-10-29 19:51:11 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-31 12:09:37 +0100 |
commit | 8936d15efa27663458a7185f29bd662e4dfc585d (patch) | |
tree | 5859eaae3b4d99b4e9b020c5b3f5983a3273674c | |
parent | 8f060bed17736bfab947d0d83272e24b691f3577 (diff) | |
download | serenity-8936d15efa27663458a7185f29bd662e4dfc585d.zip |
Calculator: Improve KeypadValue conversion to handle integer values
-rw-r--r-- | Userland/Applications/Calculator/KeypadValue.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Userland/Applications/Calculator/KeypadValue.cpp b/Userland/Applications/Calculator/KeypadValue.cpp index fbd658bddc..b677943515 100644 --- a/Userland/Applications/Calculator/KeypadValue.cpp +++ b/Userland/Applications/Calculator/KeypadValue.cpp @@ -105,9 +105,12 @@ KeypadValue::KeypadValue(double d) while (AK::pow(10.0, (double)current_pow) <= d) current_pow += 1; current_pow -= 1; - while (d != 0) { + double epsilon = 1e-6; + while (d >= epsilon || current_pow >= 0) { m_value *= 10; - m_value += (u64)(d / AK::pow(10.0, (double)current_pow)) % 10; + i8 digit = (u64)(d * AK::pow(0.1, (double)current_pow)) % 10; + m_value += digit; + d -= digit * AK::pow(10.0, (double)current_pow); if (current_pow < 0) m_decimal_places += 1; current_pow -= 1; |