From 14c405f6798031b4cc773e1c25efd01c6eaab0f8 Mon Sep 17 00:00:00 2001 From: Yash Sharma Date: Wed, 20 Sep 2023 09:28:00 +0530 Subject: [PATCH] I added comments to describe the purpose of fuctions. it's my first commit, i am looking forward to get a feedback on this. --- src/CalcManager/NumberFormattingUtils.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/CalcManager/NumberFormattingUtils.cpp b/src/CalcManager/NumberFormattingUtils.cpp index 3c5b9feba..630f96846 100644 --- a/src/CalcManager/NumberFormattingUtils.cpp +++ b/src/CalcManager/NumberFormattingUtils.cpp @@ -11,16 +11,18 @@ namespace UnitConversionManager::NumberFormattingUtils /// number to trim void TrimTrailingZeros(_Inout_ wstring& number) { + //check if the number contains a decimal point. if (number.find(L'.') == wstring::npos) { - return; + return; //no trailing zeros or decimal to trim. } + //find the last non-zero digit and erase and triling zeros. if (auto i = number.find_last_not_of(L'0'); i != wstring::npos) { number.erase(number.cbegin() + i + 1, number.cend()); } - + //remove the trailing decimal point if it exists. if (number.back() == L'.') { number.pop_back(); @@ -32,12 +34,15 @@ namespace UnitConversionManager::NumberFormattingUtils /// the number unsigned int GetNumberDigits(wstring value) { + //trim trailing zeros and decimal point. TrimTrailingZeros(value); unsigned int numberSignificantDigits = static_cast(value.size()); + //if the number contains a decimal point, reduce the count by one. if (value.find(L'.') != wstring::npos) { --numberSignificantDigits; } + //if the number is negative, reduce the count by one if (value.find(L'-') != wstring::npos) { --numberSignificantDigits;