From f25b6217a60e55763c6b44c47a1efe33dc5bfa92 Mon Sep 17 00:00:00 2001 From: azazaz123010 Date: Sun, 30 Jan 2022 17:18:22 -0500 Subject: [PATCH] 4 for bin 3 for oct --- .../StandardCalculatorViewModel.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/CalcViewModel/StandardCalculatorViewModel.cpp b/src/CalcViewModel/StandardCalculatorViewModel.cpp index caeb5bb2..addef977 100644 --- a/src/CalcViewModel/StandardCalculatorViewModel.cpp +++ b/src/CalcViewModel/StandardCalculatorViewModel.cpp @@ -137,6 +137,10 @@ StandardCalculatorViewModel::StandardCalculatorViewModel() String ^ StandardCalculatorViewModel::LocalizeDisplayValue(_In_ wstring const& displayValue) { wstring result(displayValue); + if (CurrentRadixType == NumberBase::BinBase || CurrentRadixType == NumberBase::OctBase) + { + result = AddPadding(result); + } LocalizationSettings::GetInstance()->LocalizeDisplayValue(&result); return ref new Platform::String(result.c_str()); } @@ -1545,6 +1549,24 @@ wstring StandardCalculatorViewModel::AddPadding(wstring binaryString) { return binaryString; } + if (CurrentRadixType == NumberBase::BinBase) + { + size_t pad = 4 - LengthWithoutPadding(binaryString) % 4; + if (pad == 4) + { + pad = 0; + } + return wstring(pad, L'0') + binaryString; + } + else if (CurrentRadixType == NumberBase::OctBase) + { + size_t pad = 3 - LengthWithoutPadding(binaryString) % 3; + if (pad == 3) + { + pad = 0; + } + return wstring(pad, L'0') + binaryString; + } size_t pad = 4 - LengthWithoutPadding(binaryString) % 4; if (pad == 4) {