Hi experts,
I am having problem in "converting String to Decimal."
I worte a simple function that gets values from text boxes.
It makes a calculation and returns a value.
The code is written below.
The funny thing is whent I enter values 1, xxxx, 4 , it returned 96, but when I tried 1, xxxx, 4.5 I have got "Cast from string "4.5" to type 'Decimal' is not valid." error.
How do we convert String to Decimal? please help me
Exception Details: System.InvalidCastException: Cast from string "4.5" to type 'Decimal' is not valid.
The code is:
<%@ Page Language="
VB" %>
<%@ Import NameSpace="System.Data" %>
<script runat="server">
sub Submit(Sender as Object , e as EventArgs)
Calculate(tbUserID.Text,tbPayee.Text, tbAmount.Text)
End sub
public function Calculate(UseId as Integer, payee as String, decAmount as Decimal) As String
dim tempdecAmount as decimal
tempdecAmount = Convert.ToDecimal(decAmount)
response.write(useID)
response.write(payee)
dim Balance as Decimal
if tempdecAmount <= 100 then
Balance = 100 - tempdecAmount
response.write(Balance)
end if
Return Balance
end function
</script>
<html><body>
<form runat="server">
UserID:
<asp:TextBox id="tbUserID" runat="server"/>
Payee:
<asp:TextBox id="tbPayee" runat="server"/>
Amount:
<asp:TextBox id="tbAmount" runat="server"/>
<asp:Button id="btSubmit" runat="server" text="Submit" OnClick="Submit"/><p>
</form>
</body></html>