转换成字符串值与千分十进制?

编程入门 行业动态 更新时间:2024-10-18 10:14:04
本文介绍了转换成字符串值与千分十进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这可能是一个很简单的问题。 假设文本框中显示值10,000.12当用户编辑数据被错误删除,他前两个数字像,000.12并使用该文本框在计算则给出了一个例外。我要一个公正的验证文本框

This might be a very simple question. Suppose text box show value 10,000.12 when user edits data by mistake he remove first two numbers like ,000.12 and using this textbox in the calculation then it gives an exception. I want a just validate text box.

例如:字符串str =100.12, 转换为十进制数= 100.12;

For Example: string str = ",100.12;" Convert to decimal number = 100.12;

任何想法

它?显示当用户删除任何千位分隔符仅整数。

It shows only whole number when user remove any thousand separator.

推荐答案

如果我明白的问题,你想删除将所有字符。防止解析程序从失败

If I understood the question, you want to remove all characters that would prevent the parse routine from failing.

string str = ",0,100.12"; var modified = new StringBuilder(); foreach (char c in str) { if (Char.IsDigit(c) || c == '.') modified.Append(c); } decimal number= decimal.Parse(modified.ToString());

更多推荐

转换成字符串值与千分十进制?

本文发布于:2023-10-24 20:06:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524877.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:千分   转换成   字符串值   十进制

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!