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

Is there any inbuilt function to convert a decimal number to integer in vb ?

Supposing i need to convert 12.3 to 12 or 13 depending on some criterion, do i need to get the decimal part and multiply by 10 or there is an inbuilt function to do the conversion ?
Sep 9 '10 #1

✓ answered by Guido Geurs

There is also:

When the fractional part is exactly 0.5, CInt and CLng always round it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2. CInt and CLng differ from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. Also, Fix and Int always return a value of the same type as is passed in.

Or You can use:

Expand|Select|Wrap|Line Numbers
  1.    If Val(Text1) > Int(Val(Text1)) Then
  2.       Text_roundup = Int(Val(Text1)) + 1
  3.    Else
  4.       Text_roundup = Int(Val(Text1))
  5.    End If

3 1898
Guido Geurs
767 Expert 512MB
Int(number) gives the integer of a number (see help VB).
But there are also other functions with an integer as result but with different outcome.

There is Int(number), Fix(number) and Round(expression [,numdecimalplaces])
Sep 9 '10 #2
Hi,
Thanks for the reply. I know about int(number) which gives rounddown operation result. I wanted to know if there is any roundup function as such.
Sep 9 '10 #3
Guido Geurs
767 Expert 512MB
There is also:

When the fractional part is exactly 0.5, CInt and CLng always round it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2. CInt and CLng differ from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. Also, Fix and Int always return a value of the same type as is passed in.

Or You can use:

Expand|Select|Wrap|Line Numbers
  1.    If Val(Text1) > Int(Val(Text1)) Then
  2.       Text_roundup = Int(Val(Text1)) + 1
  3.    Else
  4.       Text_roundup = Int(Val(Text1))
  5.    End If
Sep 9 '10 #4

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

Similar topics

7
by: whatluo | last post by:
Hi, all I'm now working on a program which will convert dec number to hex and oct and bin respectively, I've checked the clc but with no luck, so can anybody give me a hit how to make this done...
13
by: muss | last post by:
how to convert decimal number in a hexadecimal number using C? Please help me. Thanks.
32
by: saima | last post by:
a program that takes a decimal number input from the user and displays its binary number equivalent in 12 bits on the screen. For example: Enter a decimal number: 32 Its Binary Equivalent is : ...
14
by: dharmdeep | last post by:
Hi friends, I need a sample code in C which will convert a Hexadecimal number into decimal number. I had written a code for that but it was too long, I need a small code, so request u all to...
1
by: ahoway | last post by:
I am working on a program where I have to enter a decimal number and enter a base and it converts according to base. output: Please enter a decimal number to convert: 15 <-input What base would...
28
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
0
by: Metalpalo | last post by:
Hello everybody I created small batch file in MSDOS. In this batch file i need to print hexadecimal value of some env. variable. For example: I enter value via command :set /P PAR=Enter...
2
by: marulasiddesh | last post by:
can any one help me out in converting a decimal number to binary number?
2
by: Hets | last post by:
Write a C program which can convert decimal number into binary number.
10
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
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:
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
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
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
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...
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...

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.