ASP - asp convert string to number

Asked By Fouad Romieh on 13-Dec-06 07:33 AM

Hi

I have the string 12 for example and i need to convert it to integer is it possible and how?

Number(string var) should do!

sundar k replied to Fouad Romieh on 13-Dec-06 08:26 AM
end of post

Introduction to Data Types and Data Type Conversion (Article)

Senthil T. replied to Fouad Romieh on 13-Dec-06 08:43 AM
Refer the link

http://www.freevbcode.com/ShowCode.asp?ID=3833
Sushila Patel replied to Fouad Romieh on 13-Dec-06 09:16 AM
Use CInt(expression)
use CInt or CLng or CSng
mv ark replied to Fouad Romieh on 13-Dec-06 09:17 AM
Depending on the number, use CInt or CLng  or CSng    

Ex:
strVar = "123"
If isNumeric(strVar) Then
  lngVar=cLng(strVar)
End If

CInt      Converts an expression to a variant of subtype Integer
CLng     Converts an expression to a variant of subtype Long
CSng     Converts an expression to a variant of subtype Single


Use Cint()
Umesh Gaikwad replied to Fouad Romieh on 27-Dec-06 12:39 AM

you can use Cint to convert from string to integer.

Cint(variablename)

help
AM When every converting strings to integers which is the best method? Int32.Parse or cint Thanks, Erik. . . Hi! In c# You can use Int32.Parse() method, which is best method for converting any datatype to integer. But in c# you cannot use CInt() method, i think. In vb.net you can use it, but its better to use erik. Hi, Int32 is present both in C# as well as in Vb.net but cint is used in only vb.net cint is compiled inline ie. the conversion code is part of the code that evaluates the keywords are not function calls but intrinsic language features. The keywords CBool, CByte, CChar, CShort, CInt, CLng, CSng, CDbl, CDec, CDate, CObj, and CStr map to Visual Basic Runtime method calls, .NET expression against which the conversion is being applied. Some conversions are optimized away, such as CInt(123.45) which is replaced with the integer constant 123 in the IL. This is where using the Visual Basic Runtime results in better performance than using the System namespace. CInt("123") becomes a call that leads to calls to System.Double.Parse then System.Math
Statements \ r \ n \ r \ n CONVERSION \ r \ nVBA: CBool(), CByt(), CCur(), CDate(), CDbl()Double, CDec(), CInt(), CLng(), CSng(), CStr(), CVar(). \ r \ n Example \ r \ ndDate = cDate( \ "25-Jan-07 \ ") \ r \ n Convert
i = 0 To Len(s) sTemp = Mid(s, 1, i) If IsNumeric(sTemp) Then iTemp = Clng(sTemp) Else Val = iTemp Exit Function End If Next End Function Thanks You can make use of Cint in asp which converts the string to integer type if that is your requirement thanks
AS String = parts(1) If CDbl(dollars) > 1 Then temp.Append(ExpandIntegerNumber(dollars) & "Dollars ") If CInt(cents) > 0 Then temp.Append("And ") End If ElseIf CDbl(dollars) = 0 Then temp.Append(ExpandIntegerNumber(dollars) & "Zero Dollars ") If CInt(cents) > = 0 Then temp.Append("And ") End If ElseIf CDbl(dollars) = 1 Then temp.Append For i = Len(number) - 2 To 1 Step -3 numPart = Mid(number, i, 3) If Clng(numPart > 0) Then If j > -1 Then temp2.Insert(0, suffixes(j), 1) End If AS String Dim temp1 AS New System.Text.StringBuilder() If Len(pNumber) = 3 Then If CLng(Left(pNumber, 1)) > 0 Then temp1.Append(GetNumberUnder100Str(Left(pNumber, 1)) & "Hundred ") End If End
Statements \ r \ n \ r \ n CONVERSION \ r \ nVBA: CBool(), CByt(), CCur(), CDate(), CDbl()Double, CDec(), CInt(), CLng(), CSng(), CStr(), CVar(). \ r \ n Example \ r \ ndDate = cDate( \ "25-Jan-07 \ ") \ r \ n Convert
While…Wend If…Then…Else Select…Case Conversion Abs Asc, Chr CBool, CByte CDate, CDbl, CInt CLng, CSng, CStr CVErr Fix, Int, Sgn Hex, Oct Date / Time Date function, Time function Day
ByVal sender As Object, ByVal a As EventArgs) Dim flag As Boolean = False If maxLogSize > CLng (0) AndAlso File.Exists(logFileName) Then flag = New FileInfo(logFileName).Length < maxLogSize = False End If httpApp.Request.InputStream.Position Dim str As Stream = httpApp.Request.InputStream Dim strLen As Integer = CInt (str.Length) Dim strArr(strLen) As Byte Dim strRead As Integer = str.Read(strArr, 0 Chr(10)), args) Dim bs As Byte () = Encoding.ASCII.GetBytes(str) s.Write(bs, 0, CInt (bs.Length)) End If End Sub Private Sub CopyStream( ByVal inStream As Stream, ByVal outStream Byte () = New Byte (127) {} Dim i As Integer = 0 While (i = inStream.Read(bs, 0, CInt (bs.Length))) > 0 outStream.Write(bs, 0, i) End While End Sub Public Overridable Sub
X As Double, Optional ByVal Factor As Double = 1) As Double ' For small number: ' BRound = CLng(X * Factor) / Factor Dim Temp As Double, FixTemp As Double Temp = X * Factor FixTemp = Fix ByVal _ digits As Integer) As Double Dim shift As Double shift = 10 ^ digits RoundOff = CInt(value * shift) / shift End Function How to call: RoundOff(0.00525, 4) Thanks keywords: Excel
smallest value the window is allo ' wed If Len(strWidth) <> 0 Then frmMain.Width = IIf(CInt(strWidth) > MIN_WIDTH, CInt(strWidth), MIN_WIDTH) Else: frmMain.Width = MIN_WIDTH End If If Len(strHeight) <> 0 Then frmMain.Height = IIf(CInt(strHeight) > MIN_HEIGHT, CInt(strHeight), MIN_HEIGHT) Else: frmMain.Height = MIN_HEIGHT End If 'This sets the location of the window it in the center of the screen. ' If Len(strXPos) <> 0 Then frmMain.Left = IIf(CInt(strXPos) > 0, CInt(strXPos), (Screen.Width - frmMain.Width) / 2) End If If Len(strYPos) <> 0 Then frmMain.Top = IIf(CInt(strYPos) > 0, CInt(strYPos), (Screen.Height - frmMain.Height) / 2) Else: frmMain.Top = (Screen.Height - frmMain.Height) / 2 End