Format a number in a gridview template

Posted on 2013-06-19
Last Modified: 2013-06-19
I have a gridview template column that displays as 25.696249535833642

The display needs to be formatted to only one decimal place.  25.6 or 25.7 , Rounding is not important.

This is my column spec:

             <asp:TemplateField HeaderText="Pct Change" >
                    <asp:Label runat="server"
                        Text='<%# (Convert.ToDecimal(Eval("MaxClose")) -
                        /Convert.ToDecimal(Eval("MinClose")) *100 %>'>
                     <HeaderStyle HorizontalAlign="Left" Width="0.4in" />
                    <ItemStyle HorizontalAlign="Right" Width="0.4in" />

What do I need to change?

Question by:Dovberman
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 13

Accepted Solution

jitendra patil earned 300 total points
ID: 39259396
you can try String.Format("{0:c}", value)

  <asp:Label ID="lblText" Text=' <%# (String.Format("{0:c}", (Convert.ToDecimal(Eval("MaxClose")) - Convert.ToDecimal(Eval("MinClose"))) / Convert.ToDecimal(Eval("MinClose")) *100)) %>' runat="server"  ></asp:Label>

Hope this helps.

Author Comment

ID: 39259684
I will try your suggestion.

Meanwhile this worked:

               <asp:TemplateField HeaderText="Pct Chg" >
                    <asp:Label runat="server"
                        Text='<%# ((Convert.ToDecimal(Eval("MaxClose")) -
                        /Convert.ToDecimal(Eval("MinClose")) *100 ).ToString("F1")%>'>
                     <HeaderStyle HorizontalAlign="Left" Width="0.4in" />
                    <ItemStyle HorizontalAlign="Right" Width="0.4in" />


Author Closing Comment

ID: 39259686
Thank you.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question