How to format a decimal data type (SQL Server 2000) when displayed (in datagrid)

I have field that is decimal datatype (10,4).  Currently, when a number such as 3.25 is entered, it shows up as 3.2500 (after it is saved to the db and retrieved again).  And whole numbers, such as 44, show up as 44.0000.  I would like to have have the zeros show up at the right of the numbers.  Is there a format that will do this?  So, for 44, I really do want just 44 to show up.  And for 3.25, I really want just 3.25 to show up.
Thank you!
LVL 9
sah18Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sah18Author Commented:
Here is the column in my datagrid that is displaying this number:

<asp:TemplateColumn HeaderText="Dose">
      <ItemTemplate>
            <%# DataBinder.Eval(Container.DataItem, "dosemg") %>
      </ItemTemplate>
      <EditItemTemplate>
            <asp:TextBox Width="50px" ID="dosemg" Runat=server Text='<%# DataBinder.Eval(Container.DataItem, "dosemg") %>' />
            <asp:requiredfieldvalidator id="RequiredfieldvalidatorDosemg" runat="server" Font-Size="XX-Small" Font-Names="Webdings"
                  Display="Dynamic" ErrorMessage="=" ControlToValidate="dosemg" />
      </EditItemTemplate>
</asp:TemplateColumn>

So, I guess I need to somehow modify
<%# DataBinder.Eval(Container.DataItem, "dosemg") %>
to have the format I want in both the ItemTemplate and also the EditItemTemplate.

Any suggestions??

Thanks for your help!
GavinMannionCommented:
You will want to use the DataFormatString option the DataGrid...

Try.... dataformatstring="{0:D2}"
sah18Author Commented:
I'm just not seeing this as an option.  I only see it as an option for the BoundColumns.  Where should I place this setting?
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

tusharashahCommented:
Since you are using template column, Modify DataBinder.Eval like following:

  <%# DataBinder.Eval(Container.DataItem, "dosemg", "{0:D2}") %>

-tushar
GavinMannionCommented:
I didn't see your second post until after mine had submitted....

On a textbox I would only know how to do it using the OnItemDataBound event.

There you can access the textbox value and change it as required.

Hopefully someone else knows an easier way?
GavinMannionCommented:
Hah there you go :)
tusharashahCommented:
** you'll need to modify like following.. D2 works only with integer..

<%# DataBinder.Eval(Container.DataItem, "dosemg", "{0:N2}") %>

here's other list: http://msdn2.microsoft.com/en-US/library/31723w77(VS.80).aspx
sah18Author Commented:
tusharashah - this is getting closer to what I want, but isn't quite it!
now, i see 35.00 when I want to see 35
is there a way for it not to buffer with the trailing zeros at all?
and I don't want to truncate what has been entered at all, just display it without any extra zeros on the right.
so:  123.4567, I would still want to be displayed as 123.4567
but: 123.9000, I would want to be displayed as 123.9
do you know what i mean?
thank you again for your time!!
tusharashahCommented:
The format function will work similarly for every row, if you need certain change you can write down your own function and call it like following..

Call in your ASPX:
   <%# FormatNumber(DataBinder.Eval(Container.DataItem, "dosemg") %>

Public Function in code behind:
      public string FormatNumber(string strNumber)
      {
            if( strNumber.IndexOf(".") > -1 ) strNumber = strNumber.TrimEnd('0');
            if( strNumber.IndexOf(".") == strNumber.Length-1 ) strNumber = strNumber.Remove( strNumber.Length-1, 1);
            return strNumber;
      }

-tushar

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sah18Author Commented:
Thank you so much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.