## ProblemYou want to convert numbers to integers, or perhaps truncate or round values to integer values, and you want to understand the various ways to do this. ## SolutionAs always, use the best tool for the job. If you want to remove decimal parts of a number, consider using ## DiscussionThe following code demonstrates differences between the One important difference between The two functions are demonstrated in the following code: Dim result As New System.Text.StringBuilder Dim number As Double ' ----- Positive decimal value. number = 3.14 result.Append(number) result.Append(" CInt(): ") result.Append(CInt(number).ToString) result.Append(" Int(): ") result.AppendLine(Int(number).ToString) ' ----- Negative decimal value. number = -3.14 result.Append(number) result.Append(" CInt(): ") result.Append(CInt(number).ToString) result.Append(" Int(): ") result.AppendLine(Int(number).ToString) ' ----- Number that won't fit in an Integer. number = 3000000000.0 result.Append(number) result.Append(" CInt(): ") Try result.Append(CInt(number).ToString) Catch result.Append("(error)") End Try result.Append(" Int(): ") result.Append(Int(number).ToString) MsgBox(result.ToString()) There are some other functions in the ## Figure 6-20. The CInt( ) function converts numbers to Integer data types, while the Int( ) function returns whole numbers |

Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (OReilly))

ISBN: 0596101775

EAN: 2147483647

EAN: 2147483647

Year: 2006

Pages: 400

Pages: 400

Authors: Tim Patrick, John Craig

Similar book on Amazon

flylib.com © 2008-2017.

If you may any questions please contact us: flylib@qtcs.net

If you may any questions please contact us: flylib@qtcs.net