Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-103482

QLocale::formattedDataSize() doesn't give option to control number format

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • 5.12.12
    • Core: Locales (i18n)
    • None

      All in the title. Here is my use case :

      I want to display localized storage size, but with the following rule for the number :

      • Show 2 decimals
      • Do not show trailing zeros.

      For example, if the size is 3.58 Mb, it should be displayed as 3.58 Mb.
      If the size 3.50 Mb, it should be displayed as 3.5 Mb
      If the size is 3.00 Mb, it should be displayed as 3 Mb

      Here is my attempt to do it with QT :

      int precision = 2;
      QLocale locale = QLocale::system(); locale.setNumberOptions(QLocale::RejectTrailingZeroesAfterDot);
      return QLocale::system().formattedDataSize(bytes, precision, QLocale::DataSizeTraditionalFormat);

      What I get from this code :

      • 3.50 Mb in the first case
      • 3.00 Mb in the second case

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Eddy Edward Welbourne
            mickael.reporting Mickaƫl Da Cruz
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes