Problem showing numbers

I have put numbers in one table, bring up a another table and the numbers don’t equal the first table. I have all as Double.

325.49 becomes 325.49
3,245.62 becomes 3.00
57.00 becomes 57.00
2,552.22 becomes 2.0

I can’t figure out why this occurs. The text doesn’t help and I can’t find info when searching. DO I have a bug?

Any help would be appreciated.

Review your code, it looks like you are using something like Val to convert a string and it stops at the first comma:
https://documentation.xojo.com/api/text/val.html#val

You need to share the code that you are using for putting numbers in one table and bring up the other table.

When trying to reuse localized strings as numbers don’t use Val(). Val is for “universal” data exchange.

Val() breaks at commas, and decimal separator is ALWAYS a point “.”

To convert using the current locale string specification use ToDouble()

My locale uses commas as decimal separator and dots as decorators between thousands. It breaks the parsing in the inverse way.

1 Like

AlbertoD and Rick, thank you for the replies. I’m in the learning stage so I appreciate your efforts. I’ve removed the Val but now I’m faced with the following. It seems there is a huge learning curve!

OverviewWindow.PopulateCalculationsListBox, line 28
Parameter “value” expects type Double, but this is type String.
txtTotal.text = Format(total, “###,###,##0.00”)

My code starts here.
// Load all applicable recordSets based on the SQL statements in the Opening code
// Loop until reach end of recordSets
While not rs.eof
lb.addRow""

For i = 1 to rs.fieldCount
lb.cell(lb.lastIndex, i - 1) = rs.idxField(i).stringValue

Next
rs.moveNext
Wend

// All recordSets have been added to the CalculationsLB and must be tallied to provide
// a total to be placed in the appropriate cell of the ExpensesLB
Dim total as Double
For i = 0 to CalculationsLB.LastRowIndex
total = total + (CalculationsLB.Cell(i,4))
Next

txtTotal.text = Format(total, “###,###,##0.00”)
Return

The listbox returns a String, you can’t just remove Val from there, you need to convert the string to a number.

You may want to read Double.FromString here: Double — Xojo documentation
and do some testings.

You can also read about string.replace and string.replaceall over here: String — Xojo documentation
and maybe remove the commas on your strings numbers.

It all depends on your needs.

AlbertoD and Rick, thank you very much for your help. My problem has been fixed and it’s running fine. Never would have figured this out without your help.

1 Like

You may want to read this page of the documentation that deals with DataTypes

`[Data Type](https://documentation.xojo.com/api/data_types/index.html)`

It is a Table of Contents to convert Numbers to Strings or Values and back… and even currency !