mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-09-02 15:35:51 +00:00
Improve formatting for some strange cases.
This commit is contained in:
@@ -949,7 +949,20 @@ QString FormatCountDecimal(int64 number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString FormatExactCountDecimal(float64 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) {
|
ShortenedCount FormatCreditsAmountToShort(CreditsAmount amount) {
|
||||||
|
Reference in New Issue
Block a user