Hi all,
I have a program and I should enter an intger number, How do I check if this number is a ( 5 digits number )..
using the mod or "/" operators..
Thanks in advance,
zeid
Printable View
Hi all,
I have a program and I should enter an intger number, How do I check if this number is a ( 5 digits number )..
using the mod or "/" operators..
Thanks in advance,
zeid
expo = 1
donextexpo = true
while donextexpo
'If a num1 Mod num2 doesn't change num1 then num1 < num2.. If num1 Mod num2 = 0 then num1 = integer*num2.. Since we know num1 <= num2 in our scenario then the only possible value integer is 1
if (x mod 10^expo) = x then
if x = 10^expo then 0 = expo+1
donextexpo = false
endif
expo=expo+1
wend
numdigits = ???
'--------------------------
expo = 1
donextexpo = true
while donextexpo
if x div 10^expo < 1 then donextexpo = false
expo = expo+1
wend
numdigits = ???
There are many different possible implementations using div/mod.. These functions are VITAL to be comfortable with in many types of code.. I highly advise fully understanding this rather than just solving my simple ommisions and handing it in.. I'm purposely leaving code tags out to force you to look through it closer and there is a glaringly hilarious error in there:)..
isn't there any simpler way?
VB Code:
Private Sub Command1_Click() If IsNumeric(Text1.Text) Then If Val(Text1) = Int(Text1) And Len("" & Val(Text1)) = 5 Then MsgBox "5 digit number" Else MsgBox "not a 5 digit number" End If Else MsgBox "not a number" End If End Sub
Pradeep :)
I'm using java ... but I should do the calculation using mathmatical operations
My second example is about as simple as it gets I think..
Code:(Typecast_to_Integer) log10(number) + 1
or if log10 is not available
(Typecast_to_Integer) (log(number)/log(10)) + 1
The (typecast_to_inter) in vb is Int() btw, and Log() is Log10.. (In vb you must understand log laws to convert to another base using Log10..)
numdigits=Int(Log(x))+1
If you can use any math functions then I take back what I said about my second method..
This is a Math forum and OP never said he wants answer in VB.Quote:
Originally Posted by triggernum5
Secondly, you are mistaken about Int() in VB, it's CInt (Convert expression to Integer type) as opposed to Int (Return the Integer portion of a number).
Even in VB, Math.Log() returns you the Natural logarithm of a number, means to the base of e, and not the base of 10.
If num >= 10000 Then is5digit
i think u would need if Num>=10000 and if Num<=-10000
Thanks any way .. I figured it like this:
if num >= 10,000 and num < 100,000
:)
That and should be an or.
Umm, I think you're looking at that boolean wrong jeroen.. Oh, and sorry about my Log base goof for vb.. Just out of curiousity, are you allowed to use ANY mathematical method? Or only div/mod?
I meant domocobra's.
But zeidhaddadin is right.