Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I added comments to describe the purpose of fuctions. #2064

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/CalcManager/NumberFormattingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ namespace UnitConversionManager::NumberFormattingUtils
/// <param name="number">number to trim</param>
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();
Expand All @@ -32,12 +34,15 @@ namespace UnitConversionManager::NumberFormattingUtils
/// <param name="value">the number</param>
unsigned int GetNumberDigits(wstring value)
{
//trim trailing zeros and decimal point.
TrimTrailingZeros(value);
unsigned int numberSignificantDigits = static_cast<unsigned int>(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;
Expand Down