如何在C#中使用符号允许数值 [英] how to allow numeric value with sign in C#

查看:98
本文介绍了如何在C#中使用符号允许数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只允许+5.00或-6.0这是带有符号的数字值C#中有任何函数用于验证。其中只有数字的开头才有符号。

解决方案

如果要在字符串中存储值,则使用 string.Contains 来确定是否有多个 - 在字符串中签名。

问题没有正确制定。最有可能的是,您只需要表示数字值的某些字符串格式。这取决于数据类型,但我们假设它是'code> System.Int32 ,别名是 int 。在这种情况下,请看一下:

http:// msdn.microsoft.com/en-us/library/system.int32.tostring.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/0c899ak8.aspx [ ^ ]。



这就是你所需要的。对于其他类型,情况几乎相同。



-SA


i wnat to allow only +5.00 or -6.0 which is numeric value with sign is there any function in C# for such validation.where sign is only at start of the number.

解决方案

If you are storing values in a string then use string.Contains to figure out if there are more than one - sign in the string.


The problem is not correctly formulated. Most likely, you simply need certain string formatting representing a numeric value. It depends on the data type, but let''s assume it''s System.Int32, alias is int. In this case, take a look:
http://msdn.microsoft.com/en-us/library/system.int32.tostring.aspx[^],
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^].

This is all you need. For other type, the situation is nearly the same.

—SA


这篇关于如何在C#中使用符号允许数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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