|
-
October 25th, 2005, 07:12 AM
#1
51/2 = 26?
51/2=26?
Why visual basic rounds up this calculation. I want it to round it down in order to get the answer 25.
How must I do in order to make vb rounding the calculation down.
I have made like this:
dim result as integer
x=51
result=x/2
Last edited by JackiePaper; October 25th, 2005 at 07:16 AM.
-
October 25th, 2005, 07:21 AM
#2
Re: 51/2 = 26?
Try this instead. This is known as integer division and will always return the lower value.
-
October 25th, 2005, 07:38 AM
#3
Re: 51/2 = 26?
OK. I solved that declaring result as double
So it will calculate that 25,5. That's fine.
But if I want to do 50/2 the result will be 25. How can I show the decimal. How I get the result 25,0.
-
October 25th, 2005, 08:09 AM
#4
Re: 51/2 = 26?
If I understand your question, you could use the Format command, when displaying the answer.
eg txtBox = format(50/2,"#,##0.00")
and txtbox = format(51/2,"#,##0.00")
HTH
JP
Please remember to rate all postings. 
-
October 25th, 2005, 08:24 AM
#5
Re: 51/2 = 26?
int or fix should do that. Depending on the question what you want to do if you're dividing something that return negative values:
dim retval as integer
retval = int(51/2) ' returns 25
retval = fix(51/2) ' returns 25
retval = int(-51/2) ' returns -26
retval = fix(-51/2) ' returns -25
have a nice day
Patzer
_____________________________
Philo will never be forgotten
-
October 25th, 2005, 08:30 AM
#6
Re: 51/2 = 26?
Why don't you just use a Double data type?
i.e.
Dim retval As Double
Mike
-
October 26th, 2005, 12:13 AM
#7
Re: 51/2 = 26?
I did as jp adviced and used format control. That's was the solution my problem. First I declared the result variable as double as Pinky said. Thanks to all helped me.
Last edited by JackiePaper; October 26th, 2005 at 12:17 AM.
-
October 26th, 2005, 04:52 AM
#8
Re: 51/2 = 26?
glad to hear you came right.
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|