Why 007 show as 7 (Int, Double, Float, String)

pluton

Active Member
Licensed User
Longtime User
OK
I don't know why because I didn't test it before but today I noticed when you have number like 007 it always show without zeroes. It shows 7

Here is little code:
B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   
   Dim IdInt As Int
   Dim IdString As Int
   Dim IdFloat As Float
   Dim IdDouble As Double
   
   IdInt = 007
   IdString = 007
   IdFloat = 007
   IdDouble = 007

End Sub

Sub Activity_Create(FirstTime As Boolean)

   Msgbox("IdInt: " &IdInt _
   &CRLF& _
   "IdString: " &IdString _
   &CRLF& _
   "IdFloat: " &IdFloat _
   &CRLF& _
   "IdDouble: " &IdDouble,"OK")

End Sub

And here's what I got on emulator and phone:

image.png
or
idd.png
 

Mahares

Expert
Licensed User
Longtime User
If you declare them as strings, you will get your zeros:
B4X:
Dim IdInt As String
    Dim IdString As String
    Dim IdFloat As String
    Dim IdDouble As String
    
    IdInt = "007"
    IdString = "007"
    IdFloat = "007"
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Yes. 007=7 so no surprise you get these results,actually I would be surprised if you get something different. If you need a '007' to be displayed, you can always use the string representation, for e.g. dim s as string:s="007". Also, you can try the numberFormat functions.
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
Yes my bad. I just notice that I Dim IdString as Int and I meant As String : palmface :

I test all but type it wrong.
 
Upvote 0

Reinosoft

Member
Licensed User
Longtime User
a Int, Float and Double are numbers

the only way to show the double zero is to create a string
(i think you made the mistake to DIM idString as int; instead of dimming it as String)

if you use:

Dim idString as string
idString = "007"


it will definately work!
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
try this

B4X:
  Dim IdInt As Int
  Dim IdString As Int
  Dim IdFloat As Float
  Dim IdDouble As Double
 
  IdInt = NumberFormat(007,3,0)
  IdString = NumberFormat(007,3,0)
  IdFloat = NumberFormat(007,3,0)
  IdDouble = NumberFormat(007,3,0)
 
Upvote 0
Top