如何格式化数字字符串

DTWUJP 2008-01-19 09:29:53
比如:7.4900,7.4340,9.2000,3.2345...即截掉最后的数字0,小数位数固定为4,但也有没有以0为结尾的数字,使数字只保持有数字状态,变为7.49,7.434,9.3,3.2345,谢谢
...全文
75 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lucky749 2008-01-19
  • 打赏
  • 举报
回复
应该要一个数字串数字串取出来.然后做个函数处理小数后面的0,这个是处理小数后面的0
{
string mystr = "74.5900";
string tmpstr = mystr;
int posetion;
posetion=mystr.IndexOf(".")+1;
tmpstr = tmpstr.Substring(posetion , tmpstr.Length - posetion);
tmpstr = tmpstr.Replace("0", "");
mystr = mystr.Substring(0, posetion) + tmpstr;
Response.Write(mystr);
}
tantj 2008-01-19
  • 打赏
  • 举报
回复

double a = 7.4900;
string temp = a.ToString().Replace("0", "");
double.TryParse(temp, out a);
Console.WriteLine(a);

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧