It does not show the right format

"Dim btt, ctt As Integer
Dim lb, ib As Double
Dim nb as Double
Dim lc, nc, ic As Double

For j As Integer = 0 to BiglBox.RowCount-1 //Ripete per tutte le righe della listbox

Dim b As String =BiglBox.CellValueAt(j, 2) //Raccoglie il valore delle varie celle
Dim bb As String =CenBox.CellValueAt(j, 2) //

Dim c As String =BiglBox.CellValueAt(j, 3) //
Dim cc As String =CenBox.CellValueAt(j, 3) //

Dim d As String =BiglBox.CellValueAt(j, 4) //
Dim dd As String =CenBox.CellValueAt(j, 4) //

Dim e As String =BiglBox.CellValueAt(j, 5) //
Dim ee As String =CenBox.CellValueAt(j, 5) //

btt=btt+val(b) //Calcola i totali per i biglietti
lb = lb+val©
nb = nb+val(d)
ib = ib+val(e)

ctt=ctt+val(bb) //Calcola i totali per le cene
lc = lc+val(cc)
nc = nc+val(dd)
ic = ic+val(ee)

Next

// •••••••••••• Mostra i risultati nelle finestre dei totali •••••••••••••••

TBigl.Text=str(btt)
TLorB.Text="€ "+str(lb)
TNetB.Text=Format(nb, “\€ ##.00”) <---------------- THIS ONE
TIVB.Text=Format(ib, “\€ ##.00”)

TCen.Text=str(ctt)
TLorC.Text="€ “+str(lc)
TNetC.Text=Format(nc, “\€ ##.00”)
TIVC.Text=Format(ic, “\€ ##.00”)”

In the for/next loop 4 total values for each table are increased to show the final totals. The last 2 show, correctly, two decimal places. The first 2 are meant to show no decimal.
The one field (TNetB.Text) always show xx.00 like its parameter (nb) even though val(d) before has the correct value. It is the only one, all the others, which follow the same type of code, show the correct decimal values.
I don’t understand this behavior.

You used Format with a mask that ask for the decimal and two values after. Remove .00 in the mask to not get the decimals…

On the contrary, I need the decimals. The problem is that, no matter what the result is, they always show xx.00. For example, if the result of the sum is € 34,46, it always shows wrongly € 34,00. No decimal displayed at all.
None of the other fields behave in this way

Use ##.## instead of ##.00 ?

Are you saying that (nb) has no decimals but (d) does? Could be that those cells show a different decimal character (for your locale) and val(d) drops the decimals.

From: Val — Xojo documentation

Returns the numeric form of a string, always using US/English notation.

Notes

For localized number formatting, use the CDbl function instead. Generally, you will use Val for converting internal data and use CDbl for converting data for input and output of user data.

It is important to note that Val’ does not take separator characters into consideration. For example:

Dim d As Double
d = Val("10,000.95") // The "," causes the string to stop being converted

So d = Val(“34,46”) will make d = 34 and not 34.46 (for US or 34,46 for your locale)

1 Like

As Alberto said, the problem seems to lie on the Val(), not the Format(), I would even change the format to something like “\€ ##0.00” to have “€ 0,00” instead of “€ ,00”.

CDbl did the trick.
Thanks everybody for your help

1 Like

At he bottom of nearly all LR pages, there is a section named See Also.
Guess what you would find there in the Val page ?

https://documentation.xojo.com/api/text/val.html

Guess what appears n the first paragraph there:
https://documentation.xojo.com/api/data_types/string.html.Val

Sarcasm will not get you anywhere, even I can do it: guess why, with all your guessing, did not even come close to solve my problem while others did?

At these two pages, they talks about CDbl.

No sarcasm there.

In the old times people would say RTFM. I only gived relevant LR pages where you will found the answer (if you searched it in Val and String).

Right. Sorry I misinterpreted you. I did not go into the manual because (my fault) I took for granted that Val was just converting string into numbers right out the way they were written. I had no clue about Cdbl or anything like that. Now I know better.
After all I presumed that a Getting Started page is to learn and be guided into “adulthood” by more expert folks.
No hard feeling I hope.