473,396 Members | 1,879 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,396 software developers and data experts.

how to call out the "whole number" from "double"

jasjas
9
my Q is like this,

i want to design a calculation which use the number user enter to "/" by 100.
so , offcouse the result mayb in double or integer.
after that my calculation just wanna user the "whole number" of the result to calculate other things. can anyone help me? thks.

For eg: 9 / 2 = 4.5
and i just wanna take the number "4" to calculate other calculation.
so, how to call it out?
Jul 2 '07 #1
6 2478
Killer42
8,435 Expert 8TB
i want to design a calculation which use the number user enter to "/" by 100.
so , offcouse the result mayb in double or integer.
after that my calculation just wanna user the "whole number" of the result to calculate other things. can anyone help me? thks.

For eg: 9 / 2 = 4.5
and i just wanna take the number "4" to calculate other calculation.
so, how to call it out?
You want the Int() function. For example, if you said Result = Int(9 / 2) you would end up with 4 in Result. You can get a similar effect by simply placing the value in a "whole number" type variable (Byte, Integer, Long etc.) except that then it will be rounded to the nearest whole number, not just "chopped". In other words, if you defined variable Result as an Integer and said Result = 9 / 2 you would get 5 in Result.
Jul 2 '07 #2
jasjas
9
so , if the result is 4.99, but i oso want to use the "4" only .so what should i do?
oso use int() ?
Jul 2 '07 #3
hariharanmca
1,977 1GB
my Q is like this,

i want to design a calculation which use the number user enter to "/" by 100.
so , offcouse the result mayb in double or integer.
after that my calculation just wanna user the "whole number" of the result to calculate other things. can anyone help me? thks.

For eg: 9 / 2 = 4.5
and i just wanna take the number "4" to calculate other calculation.
so, how to call it out?

Yha its simple,

Result = 9 \ 2


then u get 4
Jul 2 '07 #4
Killer42
8,435 Expert 8TB
Result = 9 \ 2
then u get 4
Like I said, assigning it to an Integer or Long variable will round up or down to the nearest whole number, while Int() function will always round down.

I've done a bit more checking. Unfortunately, it looks as though VB actually has the rounding rules slightly wrong. 4.5 should round up to 5, but doesn't. But if for example you place 4.51 in your variable, then it will round up to 5.
Jul 2 '07 #5
kadghar
1,295 Expert 1GB
Int() gives you back the lower integer, Fix() will give you the closest to zero..

i.e:

Int (4.99) = 4
Int ( - 3.2) = -4 (see, is the one below)

and

fix (4.99) = 4
fix( - 3.2) = -3 (i've found this one more useful)

And if you want a rounded result, use round and the number of decimals, use zero decimals to round to the closest integer.
Jul 2 '07 #6
Killer42
8,435 Expert 8TB
Thanks for the extra details, kadghar. Good head-up about the "nearer to zero" thing. I always forget about the effect of negative values.

However, using Round with 0 digits seems a bit superfluous, since it produces the same result as simply placing the value into an integer field. I suppose it depends on the circumstances whether it would be worth using or not.
Jul 3 '07 #7

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

Similar topics

3
by: Mensan | last post by:
I am trying to compute the differnece between two dwords in visual basic and keep getting the wrong value being computed. I have the following structure defind: Public Type HighLowQuote...
2
by: BoĆĄtjan Jerko | last post by:
Hello! I have a list of lists (e.g. ,,]) and would like to do index on the first element of the lists. Can it be done? B.
16
by: John Baker | last post by:
Hi: I know this is a strange question, but I have inherited a system where files are copied and records re auto numbered (as an index field) )frequently, and I am wondering how high the number...
2
by: Sooha Park Lee | last post by:
I would like to compare two "double" numbers. To overcome round-off error, I am using the following strategy: rounding each number and try to convert it into interger by multiplying 10E6. One...
12
by: Assaf | last post by:
Hi all, My client is using an online service provider that processes survey responses. After a user fills survey.aspx and presses the OK button, 2 things need to happen: 1. the data has to...
7
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a...
12
by: Zero | last post by:
Hi everybody, i want to write a small program, which shows me the biggest and smallest number in dependance of the data type. For int the command could be: ...
5
by: Franky | last post by:
Can a Decimal variable be set to "Not a Number" I've been looking in the help and can't find any reference to that. Thanks in advance
3
by: hmznzr | last post by:
when a user inputs a value into a text box, i am searching that value in my dataset. although the number that i entered is in my dataset, i am getting this excemption. please help me
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.