如何写小于零的十进制值 [英] how to write decimal value greater than zero

查看:83
本文介绍了如何写小于零的十进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Haiiiii



我想检查十进制值是否大于零。请帮帮我

解决方案

  1 。假设我正在检查 a  decimal 键入
decimal valueToCheck = 1 ;
if (valueToCheck > 0
{
// 在此处做更大的提醒
}
else
{
// 做不到这里改变
}


2 。假设我正在检查 string type
string valueToCheck = 1 ;
decimal value ;
if decimal .TryParse(valueToCheck, out value )== true
{
if value > 0
{
// 在这里做更大的提醒
}
else
{
// 在此处减少提醒
}
}
其他
{
// 不是有效的十进制类型提醒
}





由于这是一个非常简单的问题,我还建议您获得一本关于C#的参考书并看一下<啊ref =http://msdn.microsoft.com/en-us/beginner/default.aspx> msdn初学者中心 [ ^ ]


有两种方法可以实现此目的。 1.直接来自Code Behind 2.使用正则表达式



1。使用Code Behind:



  if (decimalValue < span class =code-keyword>>   0 
{
// 做你的工作
}





2。使用正则表达式:



 <   asp:TextBox     runat   =  server    ID   =  textDecimal   >  <   / asp:TextBox  >  
< asp:RegularExpressionValidator runat = < span class =code-keyword> server ID = rexDecimal ValidationExpression = ^ \s *(?=。* [1-9])* \d(?: \.\d {1,5})?\s *

ControlToValidate = textDecimal ErrorMessage = 无效 > < / asp:RegularExpressionValidator >


Haiiiii

I want to check decimal vlaue is greater than zero. please help me

解决方案

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[^]


There are two ways to achieve this. 1. Directly from Code Behind 2. Using Regular Expressions

1. Using Code Behind :

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



2. Using Regular expression :

<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>


这篇关于如何写小于零的十进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆