Calculator: Improve KeypadValue conversion to handle integer values
This commit is contained in:
parent
8f060bed17
commit
8936d15efa
Notes:
sideshowbarker
2024-07-18 01:42:55 +09:00
Author: https://github.com/musabkilic Commit: https://github.com/SerenityOS/serenity/commit/8936d15efa2 Pull-request: https://github.com/SerenityOS/serenity/pull/10687 Issue: https://github.com/SerenityOS/serenity/issues/10684 Reviewed-by: https://github.com/BenWiederhake ✅
1 changed files with 5 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue