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 ?
Is there any inbuilt function to convert a decimal number to integer in vb ?
Collapse
X
-
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(expressio n [,numdecimalplac es]) -
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:
Code:If Val(Text1) > Int(Val(Text1)) Then Text_roundup = Int(Val(Text1)) + 1 Else Text_roundup = Int(Val(Text1)) End IfComment
Comment