From 8359b0cbe6aa0443d13245c7d312b5aec6c6a6cf Mon Sep 17 00:00:00 2001 From: Alex Alabuzhev Date: Fri, 26 May 2017 20:46:10 +0000 Subject: [PATCH] more 4963 --- far/changelog | 4 ++++ far/strmix.cpp | 28 ++++++++++++---------------- far/vbuild.m4 | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/far/changelog b/far/changelog index 63854bb155..46a1f4ff02 100644 --- a/far/changelog +++ b/far/changelog @@ -1,3 +1,7 @@ +drkns 26.05.2017 21:45:31 +0000 - build 4969 + +1. Продолжение 4963. + svs 24.05.2017 21:58:27 +0300 - build 4968 1. SQLite 3.19.1 diff --git a/far/strmix.cpp b/far/strmix.cpp index 232160313b..54df56476c 100644 --- a/far/strmix.cpp +++ b/far/strmix.cpp @@ -569,27 +569,23 @@ string FileSizeToStr(unsigned long long FileSize, int WidthWithSign, unsigned lo double Parts[2]; Parts[1] = std::modf(SizeInUnits, &Parts[0]); - + auto Integral = static_cast(Parts[0]); - const auto UseFixedPoint = false; // "Old" style. TODO: option? + const auto FixedPrecision = 0; // 0 for floating, else fixed. TODO: option? - if (const auto NumDigits = UseFixedPoint? 2 : Integral < 10? 2 : Integral < 100? 1 : 0) + if (const auto NumDigits = FixedPrecision? FixedPrecision : Integral < 10? 2 : Integral < 100? 1 : 0) { - auto Fractional = static_cast(std::round(Parts[1] * (NumDigits == 2? 100 : 10)) * (NumDigits == 1? 10 : 1)); - - if (Fractional == 100) + const auto AjustedParts = [&] { - ++Integral; - Fractional = 0; - } - - // Explorer-style - //auto Fractional = static_cast(Parts[1] * 100); - - const auto Div = std::div(Fractional, 10); - const wchar_t StrFractional[] = { wchar_t(L'0' + Div.quot), wchar_t(L'0' + Div.rem), L'\0' }; - Str = concat(str(Integral), locale::GetDecimalSeparator(), string_view(StrFractional, NumDigits)); + const auto Multiplier = std::pow(10, NumDigits); + const auto Value = Parts[1] * Multiplier; + const auto UseRound = false; + const auto Fractional = static_cast(UseRound? std::round(Value) : Value); + return Fractional == Multiplier? std::make_pair(Integral + 1, 0ull) : std::make_pair(Integral, Fractional); + }(); + + Str = concat(str(AjustedParts.first), locale::GetDecimalSeparator(), pad_left(str(AjustedParts.second), NumDigits, L'0')); } else { diff --git a/far/vbuild.m4 b/far/vbuild.m4 index f8641889c9..0b12fb81ca 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -m4_define(BUILD,4968)m4_dnl +m4_define(BUILD,4969)m4_dnl