Android Question Extracting commas and periods

peggjones

Active Member
Licensed User
Longtime User
I am downloading amounts into a spreadsheet which are coming in like this

£1,000.00

or £1,000.00-

I want to remove the commas and periods and end up with a value that is in pennies.

Does anyone know of a neat routine to do this or do I need to code from scratch?

I'm not asking anyone to do my coding for me, I just wondered if there is a standard way of achieving this.

Many Thanks.
 

LucaMs

Expert
Licensed User
Longtime User
I am downloading amounts into a spreadsheet which are coming in like this

£1,000.00

or £1,000.00-

I want to remove the commas and periods and end up with a value that is in pennies.

Does anyone know of a neat routine to do this or do I need to code from scratch?

I'm not asking anyone to do my coding for me, I just wondered if there is a standard way of achieving this.

Many Thanks.


I did not understand exactly what you want to achieve.

However, you can remove characters using:

B4X:
VarName = VarName.Replace (",", "")

For other things, you have to format the cell in the spreadsheet
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I don't recommend you to remove the dot. It will be easier to remove the currency character and the minus, parse the number and then multiply it by 100.

B4X:
Sub CleanNumber(s As String) As Double
 Dim sb As StringBuilder
 sb.Initialize
 For i = 0 To s.Length - 1
  Dim c as Char = s.CharAt(i)
  If IsNumber(c) OR c = "." Then sb.Append(c)
 Next
 Return sb.ToString * 100
End Sub
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
i think he means

B4X:
dim sumtxt as string
dim sum as double

sumtxt = "£1,000.00"
sumtxt = sumtxt.Replace ("£", "")
sum = sumtxt
sum = numberformat2(sum,1,0,0,false)
 
Upvote 0
Top