Remove leading zero

aaronk

Well-Known Member
Licensed User
Longtime User
Hello,

What would be the easiest way to remove leading zeros in a number?

For Example:

008 should return 8
087 should return 87
 

aaronk

Well-Known Member
Licensed User
Longtime User
Hello,

Here is what I have tried..

This works:
B4X:
Log(NumberFormat(007, 1 ,0)) ' Logs 7 - (which is what I want)
Log(NumberFormat(187, 1 ,0)) ' Logs 187 - (which is what I want)

This doesn't work:
B4X:
Log(NumberFormat(087, 1 ,0)) ' Error

Comes up with this error: integer number too large: 087

Am I using / doing it correct?
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Try use regex.replace("0"," ")
Best Regards
Theera
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
You can use something like this:
B4X:
Dim dblVal As Double
Dim strVal As String ="087"
dblVal= strVal
Msgbox(dblVal,"")  'returns 87
 
Upvote 0
Top