If my code converts a double value 12345 to text (using ToText and a Format with commas), I get an string “12,345”. But if I take that string and try to convert it back to Double (FromText), I don’t get 12,345, but rather 12. Apparently, it sees the comma, and stops converting to a number. Is there some alternative to converting a text string with commas to a number? I suppose I can do some arrangement of parsing or separating on the comma, but I would hope there is some simpler way of doing this?
What, in your computer, is the decimal character ?
A comma is (non-exclusively) used as decimal separator in German, so
Dim d As Double = Double.Parse(TextValue, New Xojo.Core.Locale("de-DE"))
Still I wonder why you get a comma instead of a dot. What locale are you using with the toText conversion?
EDIT: Sorry, I got you wrong. Use your current locale rather to get the full number.
Have you looked at CDbl
Sorry, I forgot about the European system. I am in the US. So I have numbers like 1,222,333.444 which converted to 1
But the FromText is smart enough to recognize the decimal point, so 123.45 in text becomes 123.45 correctly.
I looked at the CBL, but all of the examples are like “12345.6” which does not have any commas (to separate powers of 10^3 … thousands, millions, billions, etc.) Also the documentation say to use the older VAL if you are controlling it which I am. But I thought the FromText is the modern version of Val
Is there some function to take a string and strip out all the commas?
e.g. t = strip(“1,234,567.89”, “,”) becomes 1234567.89
[quote=399109:@Gregory Moore]Is there some function to take a string and strip out all the commas?
e.g. t = strip(“1,234,567.89”, “,”) becomes 1234567.89[/quote]
s = ReplaceAll( s, “,”, “” )
There is an example with a comma
I believe that’s exactly what you want.
The documentation also mentions
And, below the See Also part at page bottom, is a list of reading suggestions (always useful).