[Gambas-user] I create a new function to share

Benoît Minisini gambas at ...1...
Fri Jun 26 16:27:55 CEST 2009


> Pino Zollo ha scritto:
> > Il venerdì 26 giugno 2009 04:34:54 kobolds ha scritto:
> >> I create a function call FormatX() for easy formatting number, date and
> >> string . read the cctools.html for detail on how to use it .
> >>
> >> post your opinion what you think about it
> >>
> >> http://www.nabble.com/file/p24216805/cctools.tar cctools.tar
> >
> > Hi,
> > I have tried in "it_IT.utf8" environment and I get:
> >
> > FMain.Form_Open.396: comma is decimal separator         True
> > FMain.Form_Open.397: 2 347,25
> >
> > Actually puts a space in place of .
>
> With default Debian configuration, LANG=it_IT at ...33..., tried this:
>
>       label2.Text = Format(22505.6, "#,#.00")
>
>
> Results in "22 505,6" <- there is a space.
>
> -----------------
>
> Changed file "/usr/share/i18n/locales/it_IT" so the section:
>
>     LC_NUMERIC
>     decimal_point             "<U002C>"
>     thousands_sep             ""      <------------ empty string
>     grouping                  0;0
>     END LC_NUMERIC
>
>
> results in:
>
>     LC_NUMERIC
>     decimal_point             "<U002C>"
>     thousands_sep             "<U002E>"   <------- dot simbol
>     grouping                  0;0
>     END LC_NUMERIC
>
>
> ...and now it works ok.
>
> I don't know why there is this error - don't even know if this *is* an
> error, but now it works as expected. If somebody confirms to me that the
> value of *thousand_sep* should not be empty, I can post a bug to the
> maintainer of the file *BUT*:
>
> It is worth to note that in that file, a few lines above, in the section
> LC_MONETARY, the thousand separator is correctly indicated. As Benoit
> says, all this could be correct - if we want thousand separators perhaps
> we have to use the monetary notation and not a "general number" one. In
> fact, to separate the thousands is more a commercial habit than a
> general/scientific one. But if this is true, then perhaps gambas lacks a
> CURRENCY data type, or a mean to use a currency/monetary representation
> inside format$(). By the way, a CURRENCY data type could come handy by
> itself - I had some problems with rounding floating point values and, in
> all the places where calculations were done (simple additions and
> subtraction of numbers with only two decimals of precision, normal for
> currency), I had to modify the code and round down values myself - tired
> of "1.999,99999998" numbers...
>
> In other languages the CURRENCY datatype is defined as an INT64 which,
> when printed or mixed with other numerical types, is first divided (or
> multiplied) by 10000 (ten thousands). In other words, the number 22,5
> (twentytwo and a half) is stored as the integer 225000. This way, all
> rounding errors are get rid of.
>
> Regards,
> Doriano
>

I won't make a Currency data type, but you can do:

Print Format$(Amount, "$0,###.##")

to format currencies (see the documentation of Format).

Regards,

-- 
Benoît




More information about the User mailing list