summaryrefslogtreecommitdiff
path: root/Userland/Applications/Calculator/Keypad.cpp
diff options
context:
space:
mode:
authorLucas CHOLLET <lucas.chollet@free.fr>2022-09-22 16:54:46 +0200
committerTim Flynn <trflynn89@pm.me>2022-10-03 15:12:47 -0400
commitde568f87fd709f13d08a35448f2fd99badfb2ef7 (patch)
tree821a7b73b266d72c9a593651355ec7369416ce73 /Userland/Applications/Calculator/Keypad.cpp
parent164094e161de3df98a9d169161cf639af9c09a56 (diff)
downloadserenity-de568f87fd709f13d08a35448f2fd99badfb2ef7.zip
Calculator: Add a Rounding menu
This menu has three actions. Each one of them enable a different level of rounding: to 0, 2 or 4 digits.
Diffstat (limited to 'Userland/Applications/Calculator/Keypad.cpp')
-rw-r--r--Userland/Applications/Calculator/Keypad.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/Userland/Applications/Calculator/Keypad.cpp b/Userland/Applications/Calculator/Keypad.cpp
index b94fd79e2d..e1624d7a0d 100644
--- a/Userland/Applications/Calculator/Keypad.cpp
+++ b/Userland/Applications/Calculator/Keypad.cpp
@@ -113,10 +113,8 @@ void Keypad::set_to_0()
String Keypad::to_string() const
{
- // TODO: Implement custom rounding length in the calculator.
- constexpr auto maximum_precision = 6;
if (m_state == State::External)
- return m_internal_value.to_string(maximum_precision);
+ return m_internal_value.to_string(m_displayed_fraction_length);
StringBuilder builder;
@@ -136,3 +134,8 @@ String Keypad::to_string() const
return builder.to_string();
}
+
+void Keypad::set_rounding_length(unsigned rounding_threshold)
+{
+ m_displayed_fraction_length = rounding_threshold;
+}