Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just developed this window application.

I often have to display monetary values to users, and I noticed that users will not be able to tell at a glance the value of large double values,(unless there are separating gaps or comma separator that seperates multiple of thousand value like thousand , million billion etc).

Please is there a way I can make double vales to have the thousand or comma separator?
Posted
Updated 3-Oct-11 21:36pm
v2
Comments
Manfred Rudolf Bihy 3-Oct-11 12:46pm    
Which flavor of C++ are you talking about? MFC or CLI
Dalek Dave 4-Oct-11 3:37am    
Edited for Readabilty.

Double values has no separators or anything like that. All numeric values are "binary". You really need to understand what are you asking about.

Thousand or comma separators, numeric base of number presentation are, well, the features of presentation of numbers of different types as human-readable strings, no more no less. This is a matter of string formatting. In particular, see the function sprintf, http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/[^].

—SA
 
Share this answer
 
Comments
Espen Harlinn 3-Oct-11 15:34pm    
5'ed!
Sergey Alexandrovich Kryukov 3-Oct-11 18:12pm    
Thank you, Espen.
--SA
Manfred Rudolf Bihy 3-Oct-11 15:43pm    
Take a 5!
Sergey Alexandrovich Kryukov 3-Oct-11 18:12pm    
Thank you, Manfred.
--SA
I will never understand why you do not search for code first. Second line in Bing's search results yields working code sample:
Locale fun (formatting numbers)

Update
: Much better solution (recommended): Get a moneypunct facet for cout for a locale
 
Share this answer
 
v2
Comments
Emilio Garavaglia 4-Oct-11 2:57am    
That's exacly how the standar C++ shold deal with number representation: replace the num_put / num_get facet of the locale.
Here is a link to the IEEE 754-2008[^] page on wikipedia that you may find of interest. It explains what SAKryukov means by "binary".

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Oct-11 19:04pm    
Thank you for explaining what I mean; my 5.
--SA
Espen Harlinn 3-Oct-11 19:06pm    
Thanks, Sergey - I figured it might be useful :)
Hi,

If you are on Microsoft Windows you should consider using the GetNumberFormat Function[^] with the locale id of English_USA.1252

C++
TCHAR szFormatted[MAX_PATH] = {0};
LCID lc = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
GetNumberFormat(lc,0,_T("1234567.890"),NULL,szFormatted,ARRAYSIZE(szFormatted));


Best Wishes,
-David Delaune
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900