如何解决float或Double中小数点后两位的问题

wmfenglx 2005-07-15 11:00:47
我在textBox中输入12.12但输入到SQL server数据库中却是12.120000013862
我只是想要12.12怎样处理?

在数据库中12的数据,我想查询出来的内容为12.00又该如何解决?
请帮忙!
...全文
282 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
silverseven7 2005-08-01
  • 打赏
  • 举报
回复
/// <summary>
/// Values Must in the range. While Values out of range the returns are zero
/// </summary>
/// <param name="sourceText">sourceText</param>
/// <param name="numberPoint">numberPoint</param>
/// <param name="decimalPoint">decimalPoint</param>
/// <returns></returns>
//Comma Separated Values
public static string CommaSeparatedValues(string sourceText, int numberPoint, int decimalPoint)
{
string retValue = "";
double d;

if ( decimalPoint < 0 )
{
retValue = "0";
}
else
{
//Check Number
if ( Double.TryParse(sourceText, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out d) )
{
retValue = String.Format("{0:n" + decimalPoint.ToString() + "}", d);

//Check Value About decimalPoint
string checkValue = retValue.Replace(",", "");

if ( decimalPoint > 0 )
{
if ( checkValue.IndexOf('.') > numberPoint )
{
retValue = String.Format("{0:n" + decimalPoint.ToString() + "}", 0);
}
}
else
{
if ( checkValue.Length > numberPoint )
{
retValue = String.Format("{0:n" + decimalPoint.ToString() + "}", 0);
}
}
}
else
{
retValue = String.Format("{0:n" + decimalPoint.ToString() + "}", 0);
}
}

//Result
return retValue;
}
wsh236 2005-08-01
  • 打赏
  • 举报
回复
数据库数据类型设置好就可以了!
看看数据的属性!
oyljerry 2005-07-31
  • 打赏
  • 举报
回复
设置数据库数据类型
twt_726 2005-07-31
  • 打赏
  • 举报
回复
把数据库中数据类型设置成FLOAT
yitiaoming2003 2005-07-31
  • 打赏
  • 举报
回复
楼上的说法可行
okyzx 2005-07-31
  • 打赏
  • 举报
回复
那是数据库精度问题,你用NUMBERIC类型,设置一下精度

110,536

社区成员

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

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

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