473,386 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Division irregularities

Parul Bagadia
188 100+
In my assignment of converting a number from one base system to another, whenever m dividing a decimal no; an integer in dat type by some number; many irregular results are coming; which i got when i debugged my program.
For converting a no, to binary when m dividing it by 2; only for special cases like; for 7/2 i got 4 instead of 3 and hence the complete answer is changing.
For 15/16 i got 1 instead of 0.
A very small part of my one function m posting over here.
Tell me if u can point out what's wrong,
Do
reminder(j) = store Mod 2
store = store / 2
j = j + 1
Loop While (store <> 0)
Sep 16 '08 #1
9 982
debasisdas
8,127 Expert 4TB
that is because you are using variables of wrong data type . use decimal in place of integer . i hope the problem will be solved.
Sep 16 '08 #2
vdraceil
236 100+
Use int() function-it returns only the integer portion of a number.
Expand|Select|Wrap|Line Numbers
  1. dim a as integer
  2.  
  3. a=int(15/16)
  4. msgbox a
  5.  
the output is 0 and not 1.
Sep 16 '08 #3
Parul Bagadia
188 100+
that is because you are using variables of wrong data type . use decimal in place of integer . i hope the problem will be solved.
I changed my code and used DECIMAL instead of integer; but there is no such data-type itself.
Sep 17 '08 #4
vdraceil
236 100+
what about that int() fuction?useful??
Sep 17 '08 #5
Parul Bagadia
188 100+
what about that int() fuction?useful??
I dont think so, because instead of 0 m getting 1.....so its not the matter of integer; value itself is coming different..
Sep 17 '08 #6
Parul Bagadia
188 100+
Hello ppl, can sbd plz gonna tell me what magic is happening in my program?
I tried int function which is ofcourse not needed ,also done with decimal as data type in which i got syntax error there itself coz that type doesnt exist; i also wrote another function for division; but invain; m getting illogical answers as 7/2=4 instead of 3.......and so on; the same story..
Can sbd explain plz?
Sep 17 '08 #7
Possible solution:

1) Try to use "\" in the devision instead "/" (YES it's different)
Sep 17 '08 #8
Parul Bagadia
188 100+
Possible solution:

1) Try to use "\" in the devision instead "/" (YES it's different)
Yaeh it worked!
Thank you so much; m done with my complete assignment because of this suggestion.
But can u tell me how it worked?
I mean i didnt even know that this sign is used for division!...from which book or website or from where u got this?
Plz tell me; even i want to read.
Sep 17 '08 #9
n/p, I just google it because it was really strange:) here it is:

http://theopensourcery.com/vb06tut.htm

See "Table 2"
Sep 17 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Tim Rowe | last post by:
If I do from __future__ import division then eval(1/2) gives me 0.5 as expected. But if I do print input("enter a sum: ") and enter 1/2 as the sum I get 0 as if I hadn't done the import. I thought...
2
by: Sebastian Haase | last post by:
Hi, I'm interested in having more people in our lab using numarray/NumPy instead of MatLab. For that I have put together a couple useful modules and written many myself. But then I got reminded of...
5
by: Jive | last post by:
I've got a program with Python 2.3 embedded. When I try to run a script containing "from __future__ import division", I get an exception: File "main2.py", line 3 from __future__ import divison...
19
by: Imbaud Pierre | last post by:
integer division and modulo gives different results in c and python, when negative numbers are involved. take gdb as a widely available c interpreter print -2 /3 0 for c, -1 for python. more...
15
by: joel | last post by:
I have a table which I want to update by dividing one field into another. The update runs with no errors, but the results come out as only a positive integer number. The datatype for the result...
9
by: Marcin | last post by:
How I can make division of two numbers placed in arrays, example: short int a = {2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2}; short int b =...
17
by: seb.haase | last post by:
Hi, Is it true that that "Python 3000" is dead ? Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would just break to much code :-( On the otherhand I'm using Python as "Matlab...
10
by: Mike S | last post by:
Does anyone know the logic behind why in VB.NET the result of a floating-point division ('/') is -rounded- on being converted to an integer type, such as with statements like Dim x As Integer =...
2
by: kermit | last post by:
For a long time,, There has been a discussion of trueFor division versus integer division in Python. I myslef prefer that / be used for integer division since almost always, I want the...
13
by: jamesonang | last post by:
Supposed unsigned int(32 bits) is the largest number that computer can represent with a single variable. Now, i have a big integer ( less than 64 bit, but great than 32 bit) . i represent it by...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.