[TriLUG] [OT] C++ question: currency formatting like java NumberFormat in C++?
Tanner Lovelace
clubjuggler at gmail.com
Thu Jul 13 14:39:12 EDT 2006
On 7/13/06, Doug Taggart <lug at blackwizard.net> 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..
The problem here seems to be a bit of a disconnect.
Java isn't just a language. It is also a complete run-time
system where you can set various things dealing with
internationalization. As such, it's fairly easy for Java
to do this.
C++, on the other hand, because of it's C roots and it's
portability (i.e. running on many different underlying
systems, as opposed to java which only runs on one
underlying system: the java virtual machine) C++,
in and of itself, has no way of knowing what kind of
currency format you want. Therefore, there is nothing
like this at all in any C++ standard library. It looks like
it's not even in the Boost libraries (which are basically
a playpen for stuff to be included in future C++ standard
libraries).
Now, that said, there's probably a library somewhere
that will do what you want. And, searching for
"C++ number currency format" does indeed bring
up the ICU (International Components for Unicode)
library at http://icu.sf.net/. If you take a look at this page:
http://icu.sourceforge.net/userguide/formatNumbers.html
I believe this appears to be exactly what you want, right?
Cheers,
Tanner
--
Tanner Lovelace
clubjuggler at gmail dot com
http://wtl.wayfarer.org/
(fieldless) In fess two roundels in pale, a billet fesswise and an
increscent, all sable.
More information about the TriLUG
mailing list