Skip to content

Commit

Permalink
more 4963
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed May 26, 2017
1 parent 57b9e45 commit 8359b0c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 4 additions & 0 deletions 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
Expand Down
28 changes: 12 additions & 16 deletions far/strmix.cpp
Expand Up @@ -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<int>(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<int>(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<int>(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<unsigned long long>(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
{
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,4968)m4_dnl
m4_define(BUILD,4969)m4_dnl

0 comments on commit 8359b0c

Please sign in to comment.