Re: format number on gtklabel
- From: Roger Leigh <rleigh whinlatter ukfsn org>
- To: Hariyanto <xhonghar telkom net>
- Cc: gtk-list gnome org
- Subject: Re: format number on gtklabel
- Date: Tue, 15 Feb 2005 23:32:48 +0000
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hariyanto <xhonghar telkom net> writes:
> How I want to send string with number like 3456789 to GtkLabel with the output 3.456.789,00
> I try this code :
>
> str_total = g_strdup_printf("%f", dbl_total);
> str_total_formatted = g_strndup(str_total, strcspn(str_total, ".") +3);
>
> and the output : 3456789.00
>
> How to make the output : 3.456.789,00
It's locale dependent, so make sure LC_NUMERIC is set to a locale that
formats in that style (e.g. da_DK, and presumably your own). In order
to use the locale stuff in C or C++, you need to call setlocale to set
the locale stuff up.
In C:
#include <locale.h>
setlocale(LC_ALL, "");
In C++:
#include <locale>
std::locale::global(std::locale(""));
The latter should imply the former, but I'm not totally convinced
(I've seen some odd problems when using C date functions which stopped
when I added a setlocale() call).
Just to confuse things further, in C++ it's possible to define your
own locale facets to customise this yourself. Jossuttis' "The C++
Standard Library" will tell you how.
Regards,
Roger
- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>
iD8DBQFCEoaeVcFcaSW/uEgRAtKzAKCQYuNrOOnwUapFdbRilHztTAGq6QCePihk
jVqHWQoeGXEPp7S+uiGHxuY=
=sXXd
-----END PGP SIGNATURE-----
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]