Android Question Math number issue

techknight

Well-Known Member
Licensed User
Longtime User
I am working with some big numbers in my App, For example:

8073979 - 31620316 + 90953546 = 67407209 In calculator, and in VB6.

But, in B4A, I keep getting:

6.7407209E7

For me, This is undesirable, How to I fix that? I need a string representation of 67407209, Not whatever that decimal thingy is.

Thanks.
 

techknight

Well-Known Member
Licensed User
Longtime User
Nevermind, I was assigning the result into a String, and I changed it to assign the result into an Integer, then copy the Integer into the string.

That worked.

VB6 has ruined me over the years, trying to port old apps to Droid.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Nevermind, I was assigning the result into a String, and I changed it to assign the result into an Integer, then copy the Integer into the string.

I am glad you got it sorted out, but in a case like that where you are dealing with that big number, you are always better off using the function numberformat2:
B4X:
Dim strNumber As String =NumberFormat2(8073979 - 31620316 + 90953546 ,1,0,0,False)   
Log("My Number as as string: " & strNumber)     'displays: 67407209
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Well speaking of which, I just ran into a new problem.

I have a String = 21269873164351

If I assign that string to an int, I get this:

2147483647

What the heck? how to fix?

Applying your solution of:

varMathString = NumberFormat2(Val(varMathString) + Val(varRandNum(1)) - Val(varRandNum(2)), 1, 0, 0, False)

Seemed to fix it. Go figure.
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
If I assign that string to an int, I get this:

This big number 21269873164351 is not Int. It is long.
B4X:
'This works:
    Dim MyLong = 21269873164351 As Long
    Dim strNumber As String =NumberFormat2(MyLong ,1,0,0,False)  
    Log("My long Number: " & strNumber)
  
    'This does not work:
    Dim MyInt = 21269873164351 As Int
    Dim strNumber As String =NumberFormat2(MyInt ,1,0,0,False)  
    Log("My Int Number: " & strNumber)
 
Upvote 0
Top