Click here to Skip to main content
15,896,502 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Haiiiii

I want to check decimal vlaue is greater than zero. please help me
Posted
Comments
Khandwawala Hatim 15-Oct-13 5:59am    
where do you want to check it. i mean at server side or in Regular expression
Ankur\m/ 15-Oct-13 6:09am    
what's wrong with if (variableName > 0) ?

C#
1. assuming that the value I am checking is a decimal Type
decimal valueToCheck = 1;
if(valueToCheck > 0)
{
 //do greater alert here
}
else
{
 //do less than alter here
}


2. assuming that the value I am checking is a string type
string valueToCheck = "1";
decimal value;
if(decimal.TryParse(valueToCheck, out value) == true)
{
  if(value > 0)
  {
    //do greater alert here
  }
  else
  {
   //do less alert here
  }
}
else
{
 //not a valid decimal type alert
}


As this is a very simple question I would also suggest that you get a reference book on C# and have a look at the msdn beginner center[^]
 
Share this answer
 
There are two ways to achieve this. 1. Directly from Code Behind 2. Using Regular Expressions

1. Using Code Behind :

C#
if (decimalValue > 0)
{
 // Do your work
}


2. Using Regular expression :

XML
<asp:TextBox runat="server" ID="textDecimal" ></asp:TextBox>
            <asp:RegularExpressionValidator runat="server" ID="rexDecimal" ValidationExpression="^\s*(?=.*[1-9])\d*(?:\.\d{1,5})?\s*$" ControlToValidate="textDecimal" ErrorMessage="Invalid"></asp:RegularExpressionValidator>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900