[英]Decimal Thousand Separator and Decimal Point
I googled the web for hours but couldn't find my answer. 我在网上搜索了几个小时,但找不到答案。 I need when a user types or copies any number in TextBox then the number should follow the bellow rules: 当用户在TextBox中键入或复制任何数字时,我需要该数字应遵循以下规则:
Update For example, 更新例如
123 => 123 123 => 123
1234.00 => 1,234 1234.00 => 1,234
123456.05 => 123,456.05 123456.05 => 123,456.05
123456.50 => 123,456.5 123456.50 => 123,456.5
How can I do this? 我怎样才能做到这一点?
The easiest way would be to try to parse value as a number. 最简单的方法是尝试将值解析为数字。
decimal value;
if(decimal.TryParse(textBox.Text, out value)
{
//value is ok
textBox.Text = string.Format("{0}", value);//If you want some fancier formatting
}
else
{
//Value is not valid
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.