Formatting a Number in Listbox (DBkit)

Hi there,

Using the Desktop example provided with Xojo, I am trying with no success to figure out how to format the Amount column as “monetary” (like $ 123,456.00).

if you share what you tried…

Currency is the name.

Why $ ?

Check locale

How the values are stored in the DB ?

To get the results you want, it will depend on the datatype of the source value, i.e., Integer, Double or Currency, and what locale you are outputting (whether local or another region).

Var testFRlocale As New Locale("fr-FR") // for example purposes

Var tmpInt As Integer = 123456
Me.AddRow(tmpInt.ToString(Locale.Raw, "$ #,###.00")) // $ 123,456.00
Me.AddRow(tmpInt.ToString(Locale.Current, "$ #,###.00")) // results depend on your region
Me.AddRow(testFRlocale.CurrencySymbol + tmpInt.ToString(testFRlocale, " #,###.00")) // € 123 456,00

Var tmpDbl As Double = 123456.0
Me.AddRow(tmpDbl.ToString(Locale.Raw, "$ #,###.00")) // $ 123,456.00
Me.AddRow(tmpDbl.ToString(Locale.Current, "$ #,###.00")) // results depend on your region
Me.AddRow(testFRlocale.CurrencySymbol + tmpDbl.ToString(testFRlocale, " #,###.00")) // € 123 456,00

Var tmpCur As Currency = 123456.0
Me.AddRow(tmpCur.ToString(Locale.Raw)) // 123456
Me.AddRow(tmpCur.ToString(Locale.Current)) // results depend on your region
Me.AddRow(tmpCur.ToString(testFRlocale)) // 123 456,00 €

There is also the Format() function, but that depends on whether you’re concerned about displaying a specific locale formatting.

1 Like

I used the Dollar monetary sign as I supposed many users where from USA.

My code is as follow:

//Load the invoices for this customer
Var IDinvoice As Integer = row.Column(Me.PrimaryKeyColumn).IntegerValue

SearchResultsLignesFacture.RemoveAllRows

Var rs As RowSet = Me.Connection.SelectSQL("SELECT * FROM " + TableConnectionLignesFacture.Table + " WHERE InvoiceNo = ?", IDinvoice.ToString)

// AFFICHAGE DES FACTURES LIEES A LA PERSONNE AFFICHEE
SearchResultsLignesFacture.QueryRows = rs

Return True

The value stored in the DB is Float type

If I understand well I can’t use my code to format the values as monetary but I have to loop the records in the RowSet?

Currency is the correct word.

I already shared it in this forum, but you will learn a lot from it (use current version to open / read / execute it).

It creates a Data Base file, save Currency (as €), dates as Italian format, etc. and read / display the whole back to a ListBox.
Currency in SQLite.zip (11.0 KB)

At last, you my want to use not only $, but some other like €. So, knowing to use Locale is required.

Of course, your software, your design / requirements.

1 Like

Hi Yann, did you try looping through the RowSet and formatting each value before adding it to the ListBox? Also, are you using a specific Locale for currency formatting, or do you want it to adapt to the user’s region automatically?

Hello Usha,

No, I was trying to use the DBkit only

SearchResultsLignesFacture.QueryRows = rs