Numeric Formatting

How do I format numerics into strings using GetNumberFormat().

I am most interested in how to get the +/- signs to appear where needed.... I am having a hard time getting +1.231 to come out properly...
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try to change
HKEY_CURRENT_USER\Control Panel\International\sPositiveSign
to '+'
Dak_ProgrammerAuthor Commented:
yes - I could go that route -- but I want this to work for different all other locales as well....
What SetLocaleInfo with LOCALE_SPOSITIVESIGN as locale type doesn;t work for you?
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Dak_ProgrammerAuthor Commented:
nope here is my code -- no plus signs appear with this code...

     strcpy(lpszValue, "21121.212");

     LCID lcid = m_comboLocale.GetItemData(nIndex);

     // create a locale helper
     CLocaleInfo locale(lcid);
     // construct a NUMBERFMT structure
     NUMBERFMT nmFormat;
     nmFormat.NumDigits = 4;
     nmFormat.LeadingZero = locale.GetLeadZeros();
     nmFormat.Grouping = locale.GetGrouping();
     TCHAR lpszDec[10];
     // get the decimal separator
     locale.GetDecimalSep(lpszDec, 10);
     nmFormat.lpDecimalSep = lpszDec;
     // see if we should use the thousands separator
     TCHAR lpszThousands[10]=_T("");
     locale.GetCurrencyThousandsSep(lpszThousands, 10);
     nmFormat.lpThousandSep = lpszThousands;
     nmFormat.NegativeOrder = locale.GetNegOrder();
     ::SetLocaleInfo(lcid, LOCALE_SPOSITIVESIGN, "+");
     // format the number
     ::GetNumberFormat(lcid, 0, lpszValue, &nmFormat, lpszNumber, nMax);
2 Dak_Programmer
It seems that Microsoft simple ignore LOCALE_SPOSITIVESIGN.
MSDN: "sPositiveSign ... If an application calls the GetNumberFormat or GetCurrencyFormat API, the system will use the default symbol for the locale." (default symbol = blank)

Try to add positive sign yourself.
Dak_ProgrammerAuthor Commented:
so you are telling me that there is no way to get GetNumberFormat to return me a +1.21 -- that sucks
>there is no way
To be correct - I can't see now the legal way to do it.
This info is only in the MSDN CD not in
you can do like this:
int number=1.231;
CString CStrnumber;
so the CStrnumber="+1.231";
Dak_ProgrammerAuthor Commented:
This doesn't take into account locale information....
Well, unfortuanatly the only way I see how it can work like this:

TCHAR szPlusSignBuffer[6];
GetLocaleInfo(whater locale you are looking at,LOCALE_SPOSITIVESIGN,szPlusSignBuffer,6);

int ix;

::GetNumberFormat(lcid, 0, lpszValue, &nmFormat, lpszNumber, nMax);

if(ix > 0)

Yes I know it's not exactly what you were looking for, but at this moment I can't help you more that that :-(

Dak_ProgrammerAuthor Commented:
Well I am still hoping that there is a better method for this...

You can use GetCurrencyFormat rather than GetNumberFormat.  Set
   CURRENCYFMT.lpCurrencySymbol= "+";

But this whole discussion is out of whack.  What international locale expects a leading plus sign on positive values?  I'll answer: None.   So you are doing some oddball mod to the number for your own reasons.  In that case, just stick a "+" in front of the number whenever it is a positive value.

-- Dan

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dak_ProgrammerAuthor Commented:
thanks for your comments -- and I guess I agree with your final point... maybe I am trying to do something out of whack -- but it to me it seems like something someone may like to do... thanks for your help anyways
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.