Limit a float value to two decimal places Before it is changed to a string and called by an asp:literal

I am new to C#, so I need to limit a string or float to one decimal places...

 float grossYearly = System.Convert.ToSingle(txtField1.Text.ToString());      
float newGross = grossYearly/12;      
float monthly = System.Convert.ToSingle(txtField2.Text.ToString());                
float total = monthly / newGross;              
float newTotal = total*100;                  
string i = newTotal.ToString();
                        Panel2.Visible = false;
                        Panel1.Visible = true;

then it is called here...
<asp:Literal id="Literal1" runat="server"></asp:Literal>%

I know there is a simple answer, but there are a lot of issues with testing here, so I need to be sure...Thanks.
Who is Participating?
prairiedogConnect With a Mentor Commented:
Do this then:
string i = newTotal.ToString("0.0");
theclassicAuthor Commented:
Sorry, I misprinted the title, it should read one decimal place....
Joel CoehoornDirector of Information TechnologyCommented:
Use a format string.

2 decimal places:
string i = newTotal.ToString("F2");

1decimal place:
strign = i newTotal.ToString("F1");

Standard format strings:

Custom format strings:
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Do you care if the number is rounded up?
theclassicAuthor Commented:
It just needs to be rounded, as in 1.35 would be 1.4....
theclassicAuthor Commented:
Thank you so much !
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.