?
Solved

Format a number in a gridview template

Posted on 2013-06-19
3
Medium Priority
?
637 Views
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" >
                    <ItemTemplate>
                    <asp:Label runat="server"
                        Text='<%# (Convert.ToDecimal(Eval("MaxClose")) -
                        Convert.ToDecimal(Eval("MinClose")))
                        /Convert.ToDecimal(Eval("MinClose")) *100 %>'>
                    </asp:Label>
                    </ItemTemplate>
                     <HeaderStyle HorizontalAlign="Left" Width="0.4in" />
                    <ItemStyle HorizontalAlign="Right" Width="0.4in" />
                </asp:TemplateField>

What do I need to change?

Thanks,
0
Comment
Question by:Dovberman
[X]
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
3 Comments
 
LVL 13

Accepted Solution

by:
Jitendra Patil earned 1200 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.
0
 

Author Comment

by:Dovberman
ID: 39259684
I will try your suggestion.

Meanwhile this worked:

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

Thanks
0
 

Author Closing Comment

by:Dovberman
ID: 39259686
Thank you.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

801 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