Android Question Generate number return invalid number

nickysuwandi

Member
Licensed User
I want to generate number automaticly, like example below this

185678941238
185678941239
185678941240
185678941241
185678941242
185678941243
185678941244
185678941245
185678941246
185678941247

This my code

B4X:
Dim strno As String ="185678941238"
    For intno =0 To 10
        If intno>0 Then
            strno=strno+intno
        End If
        Log(intno & ". " & strno)
                    
    Next
but the result like this :

B4X:
0. 185678941238
1. 1.85678941239E11
2. 1.85678941241E11
3. 1.85678941244E11
4. 1.85678941248E11
5. 1.85678941253E11
6. 1.85678941259E11
7. 1.85678941266E11
8. 1.85678941274E11
9. 1.85678941283E11
10. 1.85678941293E11
Anyone know where is wrong ??, this don't happen when i use only 4 or 5 digit number.

Thanks
 

emexes

Well-Known Member
Licensed User
NumberFormat2

plus keep in mind that doubles only go to 16 decimal places

although perhaps the numeric string is actually being cast to a long, but then I wonder why it resorts to e-notation which I though was a floating-point thing
 

emexes

Well-Known Member
Licensed User
If you only ever increment by 1, then you can increment strno without conversion to numeric type and back. I use this when doing variable-length binary or octal or hexadecimal or alphabetical sequences.
 

emexes

Well-Known Member
Licensed User
like this

185678941238
185678941239
185678941240
185678941241
185678941242
185678941243
185678941244
185678941245
185678941246
185678941247
That doesn't quite match your code sample, where eg the increment is increasing, but I think anyway that your immediate problem is more like: how to get rid of the E-notation eg E+11
 
Last edited:

emexes

Well-Known Member
Licensed User
Try this:

B4X:
Dim strno As String = "185678941238"

For intno = 0 To 10
    If intno > 0 Then
        strno = NumberFormat2((strno + intno), 1, 0, 0, False)
    End If

    Log(intno & ". " & strno)   
Next
 
Last edited:

emexes

Well-Known Member
Licensed User
And if that skips a bit because it's maybe still going through the E-notation wringer somewhere, try:

B4X:
Dim strno As String = "185678941238"

For intno = 0 To 10
    If intno > 0 Then
        dim L as long = strno
        L = L + intno
        strno = L    'or if you still get E-notation, try: strno = NumberFormat2(L, 1, 0, 0, False)
    End If

    Log(intno & ". " & strno)  
Next
 

emexes

Well-Known Member
Licensed User
Of course, that begs the question of: why not just store that long (integer) number As Long rather As String?
 

klaus

Expert
Licensed User
Twp problems:
1. The scientific notation.
2. He adds 1,2,3,4 etc instead of 1 !!!

Try this:
Dim strno As String ="185678941238"

For intno = 0 To 9
If intno > 0 Then
strno = NumberFormat2((strno + 1), 1, 0, 0, False)
End If
Log(intno & ". " & strno)
Next


Or with the Long variable type.
 
Top