Difficulties with Format function

Hello All!

I am migrating from VB6 which has a FormatNumber function for numbers and another FormatCurrency for money.

I’m in Brazil, where the decimal separator is the comma; (here to represent a thousand and fifty cents we do thus: 1.000,50 )

Reading the documentation of the Xojo Format function, I’m having some trouble representing integer and decimal values from a PostGres base.

This is my simplified table creation SQL:

create table cars_refuel ( id serial primary key, fuelam numeric(12,2) default 0 not null, mileage integer not null );

I populated the recordset with a very simple select (for example):

select avg(fuelam) as media from cars

when I try to show media I always got this value : 0.5 (with dot, and I wish (0,50) comma) (with Data.Field("media").StringValue).

Then I implement this to try convert:

Format(Data.Field("media").DoubleValue, "#.##0.00") and I receive a value ‘’" (blank)

This code does not work too:

Data.Field("media").CurrencyValue.ToText --> return “0.5”

Could someone help me?

Source: https://documentation.xojo.com/api/text/format.html
Emphasis mine.

I know this @Tim Parnell ; my Windows is pt-BR; but the result is wrong. (I’m using xojo WEB, maybe tis is a problem)

Your sample code includes the wrong separators though. The Format function takes the U.S. characters and will output a result that matches the localization of the system it’s being run on.

please note that postgres has a money field type that is made for this.
then you can use the currency data type in xojo.
be aware that there is a bug (?) you cannot use rs.field("fuelam").currencyvalue often gives you a zero
(at least on my french system may be it works on a US system ?)
I made a method toCurrency that converts a string into a currency data type
and I use rs.field("fuelam").stringvalue.toCurrency to get my value.

Currency.ToText information doesn’t say that will use the locale settings (even when it is expected), a little test on a system with decimal character (,) instead of (.) and this code:

Dim m As Currency = 0.5 lb1.Text = m.ToText lb2.Text = Format(m, "#,##0.00")
Will result in:

0.5 0,50
At least on my computer.

Note: my system usually use . as decimal separator, I changed that on setting for the test.