dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: formating a number

  1. #1
    Join Date
    Mar 2007
    Posts
    238

    formating a number

    Hi All,
    I can't figure out a direct answer to what i am looking for.
    I want to display a ulonglong or LARGEINTEGER with commas. I actually format it in a string like this
    Code:
    
    strNo.Format("%u", no); //for ulonglong
    strNo.Format(%64u", uno) //for LARGEINTEGER
    I want to be able to add commas preferably according to the region, any help?

    THanks

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,624

    Re: formating a number

    Did you try GetNumberFormat API?
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2007
    Posts
    238

    Re: formating a number

    Thanks for that. But i have an issue, it automatically adds .00 at the end?

    Does the Local_user-default picks up the number format from the controlpanel regionalsettings?

    Code:
    TCHAR buf[80];
    CString strSome = _T("9080093903");
    int i = ::GetNumberFormat(LOCALE_USER_DEFAULT,NULL,strSome,NULL, buf,sizeof(buf));
    
    
    returns 9,080,093,903.00 //I would like to see just 9,080,093,903
    Any clue?

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,624

    Re: formating a number

    You can get the decimal separator using GetLocaleInfo API with LOCALE_SDECIMAL parameter.
    Then - fill in the NUMBERFMT structure using obtained decimal separator value and pass it in GetNumberFormat
    Victor Nijegorodov

  5. #5
    Join Date
    Mar 2007
    Posts
    238

    Re: formating a number

    I know what you mean, but not sure how to go about it. Can you please provide me with code sample.

    THanks.

    Code:
    TCHAR cSeparater[4];
    int ii = ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, cSeparater, sizeof(cSeparater));
    Last edited by tarunk; December 3rd, 2008 at 07:53 AM.

  6. #6
    Join Date
    Mar 2007
    Posts
    238

    Re: formating a number

    I believe i did it.

    Code:
    TCHAR cLeadZero[3];
     ii = ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO, cLeadZero, sizeof(cLeadZero));
    NumFmt.LeadingZero=_ttoi(cLeadZero);
    in the same way getLocalinfo of all the variables of NumberFormat except NumDigit(set that to 0) and it works.

    Please let me know if this is wrong.

    Thanks you so much for your help.
    Last edited by tarunk; December 3rd, 2008 at 08:26 AM. Reason: tabbing

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,624

    Re: formating a number

    Quote Originally Posted by tarunk View Post
    Code:
    TCHAR cLeadZero[3];
     ii = ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO, cLeadZero, sizeof(cLeadZero));
    NumFmt.LeadingZero=_ttoi(cLeadZero);
    in the same way getLocalinfo of all the variables of NumberFormat except NumDigit(set that to 0) and it works.

    Please let me know if this is wrong.
    Why wrong?
    It is right (because it "works"!)
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)