[TriLUG] [OT] C++ question: currency formatting like java NumberFormat in C++?

Doug Taggart lug at blackwizard.net
Thu Jul 13 15:42:29 EDT 2006


Thanks,

 using fixed, showpoint manipulators and setprecision(2) seems to get me 
90% of the way there, then just putting "$" in front of everything via 
string literal
gets me 95% of the way there.   Just seems that there ought to be a 
cleaner javaesque way.

I'll have to dig through the ICU link that Tanner provided though, that 
"seems" to be what I was actually looking for on initial scan of it.

I also found this link from the setiosflags hint you gave me:
http://www.cplusplus.com/ref/iostream/ios_base/fmtflags.html
(more to read yet.. good stuff though)

Thanks for the hints to both of you..  ;)

Brian Henning wrote:

> If you're using streams, you can use ios::setiosflags and 
> ios::setprecision (I think...it's been a really long time since I've 
> used that) to set number format.  Check out (I know, I know...) the 
> MSDN language reference.  Despite being born of our hated enemy, it's 
> really a pretty good reference.
>
> Here's a link into its discussion of the iostream object:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang98/html/_iostream_ios.asp 
>
>
> Look at the "Manipulators" section, as well as the definitions of the 
> lFlags.
>
> ~B
>
>
>
> Doug Taggart wrote:
>
>> Hello,
>>
>> I'm hoping someone can help me with something that I think should 
>> have been easy for me to find.
>>
>> I'm coding a C++ program.  I have a need to format a number for 
>> currency display.
>>
>> In Java, I would use this for a quick and dirty way of getting US 
>> dollars (not checking for international stuff).
>>
>> NumberFormat currency = NumberFormat.getCurrencyInstance();
>> Then wherever I needed too I could.
>> currency.format(myNumericVariable)  into a section of code that 
>> displayed the return value as nice nifty US dollars complete
>> with $, decimal point and ,'s as appropriate.
>>
>> =====
>>
>> I can't seem to find something similar as part of the standard c/c++ 
>> libraries, which I find hard to believe.
>> I'm sure I'm just not searching for the right terms, "NumberFormat", 
>> "currency", "money", "formatting" etc..
>>
>> Anyway, pointers appreciated..
>>
>> Doug T
>>
>




More information about the TriLUG mailing list