Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GetNumberFormat for integer values

GetNumberFormat for integer values

Scheduled Pinned Locked Moved C / C++ / MFC
json
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lakitu
    wrote on last edited by
    #1

    I'm trying to use the GetNumberFormat API for integer values. No fractional digits and no decimal seperator should appear in the output. I want to use the API to account for locale settings. The results should look similar to the file sizes in Explorer's File Properties dialog.

    D 1 Reply Last reply
    0
    • L Lakitu

      I'm trying to use the GetNumberFormat API for integer values. No fractional digits and no decimal seperator should appear in the output. I want to use the API to account for locale settings. The results should look similar to the file sizes in Explorer's File Properties dialog.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Ok, so what's the problem? Do you have a code snippet that is producing a compiler or run-time error?

      NUMBERFMT fmt = {0,0,3,"",",",1};
      char szNumber[16] = "123456",
      szFmtNumber[16];
      GetNumberFormat(GetThreadLocale(), 0, szNumber, &fmt, szFmtNumber, sizeof(szFmtNumber));

      L 1 Reply Last reply
      0
      • D David Crow

        Ok, so what's the problem? Do you have a code snippet that is producing a compiler or run-time error?

        NUMBERFMT fmt = {0,0,3,"",",",1};
        char szNumber[16] = "123456",
        szFmtNumber[16];
        GetNumberFormat(GetThreadLocale(), 0, szNumber, &fmt, szFmtNumber, sizeof(szFmtNumber));

        L Offline
        L Offline
        Lakitu
        wrote on last edited by
        #3

        I don't get an error, I don't want to use the NUMBERFMT structure but use the user locale settings for the number format, only without the fractional part. Maybe there's an API to get the number format, but apparently it's not GetNumberFormat :doh: And I wanted to avoid having to call GetLocaleInfo for each member of the NUMBERFMT struct.

        D 1 Reply Last reply
        0
        • L Lakitu

          I don't get an error, I don't want to use the NUMBERFMT structure but use the user locale settings for the number format, only without the fractional part. Maybe there's an API to get the number format, but apparently it's not GetNumberFormat :doh: And I wanted to avoid having to call GetLocaleInfo for each member of the NUMBERFMT struct.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          You can't eat your cake and have it too. The whole premise behind using locale settings is so that applications won't make assumptions as to what the user wants. If the user sets up their machine to have , (comma) as the thousands separator, you mustn't override that with something else, or remove it altogether. Same goes for fractional digits, decimal points, negativity, etc. I have a slightly similar situation with the project I am working on. It's a scheduling application, which makes heavy use of dates and times. The application has to work no matter what locale it is in, or what regional settings are in place. Luckily, the NLS functions minimize the pain.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups