Search code examples
c#asp.netfloating-pointtypeconverter

different presentation of a float number in DB and webform


I have a column named point in my database that its type is float .But when i try to read the value point column it shows me something like this :

2.000000000000000e+000

While the number is 2 why?I need to show me 2.

Here is the code that i read the value

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;

Best regards


Solution

  • You didn't specify how may decimals you want to see. Possible solutions

     //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