mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-21 13:12:50 +02:00
Improve formatting for some strange cases.
This commit is contained in:
parent
628c36c87d
commit
154c777788
1 changed files with 14 additions and 1 deletions
|
@ -949,7 +949,20 @@ QString FormatCountDecimal(int64 number) {
|
|||
}
|
||||
|
||||
QString FormatExactCountDecimal(float64 number) {
|
||||
return QLocale().toString(number, 'f', QLocale::FloatingPointShortest);
|
||||
const auto locale = QLocale();
|
||||
if (qFuzzyCompare(number, base::SafeRound(number))) {
|
||||
return locale.toString(int64(base::SafeRound(number)));
|
||||
}
|
||||
|
||||
// Somehow using QLocale::FloatingPointShortest sometimes produces
|
||||
// "0.8500000000000001" on some systems / locales,
|
||||
// so I want to stick to 6 digits max (default third argument value).
|
||||
auto result = locale.toString(number, 'f');
|
||||
const auto zero = locale.zeroDigit();
|
||||
while (result.endsWith(zero)) {
|
||||
result.chop(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ShortenedCount FormatCreditsAmountToShort(CreditsAmount amount) {
|
||||
|
|
Loading…
Add table
Reference in a new issue