DB和webform中浮点数的不同表示

时间:2014-06-29 09:43:44

标签: c# asp.net floating-point typeconverter

我的数据库中有一个名为point的列,其类型为float。但是当我尝试读取值point column时,它会显示如下内容:

2.000000000000000e+000

虽然数字为2,但为什么?我需要告诉我2

这是我读取值

的代码
public class viewpointShow
        {
            public string viewPointId { set; get; }
            public string point { set; get; }
            public string question { set; get; }
            public string JurorUserName { set; get; }
            public string articleId { set; get; }

        }
     List<viewpointShow> q =
                    (dbcontext.tblPoints.Where(i => i.ArtichleId.Value == int.Parse(articleId))
                              .Select(arg => new viewpointShow()
                                  {                             
                                     JurorUserName =arg.JurorUsername,
                                     articleId = arg.ArtichleId.ToString(),
                                     point = arg.Point.ToString(),
                                     question = ReturnQuestionById(arg.QuestionId.Value) 
                                  })).ToList();
            return q;

祝你好运

1 个答案:

答案 0 :(得分:1)

您没有指定想要查看小数的方式。可能的解决方案

 //point = arg.Point.ToString()
   point = arg.Point.ToString("0.0", CultureInfo.InvariantCulture)    // always 1 decimal digit
   point = arg.Point.ToString("#.##", CultureInfo.InvariantCulture)   // at most 2