Solved

i cannot format my values as i want, i need to know how to add 0 on right of the number, how to do it?

Posted on 2008-10-08
4
226 Views
Last Modified: 2013-12-17
hello,
i'm receiving values,  as follow:
2.23
1.1
0.34
2.2

what i'd like to have then is  two values after the coma,  as follow
2.23
1.10
0.34
2.20

i've been trying to do it with the following method.
    double _tempVal = double.Parse(row["weight"].ToString());
   //String.Format("{0:0.00}", _tempVal);   <-- did not doit
    String.Format("{0:#,##0.00}", _tempVal); <-- ko also

i use then the value to create an html table
 _builder.Append("<td width=200>");
      _builder.Append(_tempVal);
 _builder.Append("</td>");

the problme is that i never succeed with two decimals(two values on right of the coma)

thank you in advance for solution with explanation,
   ......
0
Comment
Question by:toshi_
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Ramuncikas
Comment Utility
double _tempVal = double.Parse(row["weight"].ToString());
...
 _builder.Append(_tempVal.ToString("#,##0.00"));
0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 100 total points
Comment Utility
if you want to convert 1.1 to 1.10 then use
(1.1).ToString("0.00");
0
 

Author Comment

by:toshi_
Comment Utility
thank Ramuncikas and ragi0017 for your reply,

when i generate my html, i use it then to generate an xls file.

....
  Response.Clear();
            Response.Buffer = true;
            Response.ContentType = "application/vnd.ms-excel";
            //Response.ContentEncoding = System.Text.Encoding.GetEncoding("iso-8859-2");
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.Charset = "";
            this.EnableViewState = false;
            Response.AddHeader("Content-Disposition", "filename=ContainerDrain_.xls");
            Response.Write(PrepareCompleteOutputForExcel().ToString());                              <--- my html
            Response.End();
.....

as your 2 comment are not changing anything, they are not changing 1.1 to 1.10,
i 'm wondering if the issue is from my excel export,

how to check ?
what to do ?
any idea??

As the probleme seem more complicated i'll give more  points for the question , up to 500.-
0
 
LVL 14

Accepted Solution

by:
Ramuncikas earned 400 total points
Comment Utility
By default Excel trims down trailing zeros from numbers after comma. If you open excel, write some number like 12.3400 you'll see that trailing zeros are gone after you hit ENTER key. That is a problem not relating to ASP.NET.

Try changing downloaded file's extension to .txt and open it in notepad. You'll see HTML code in there. If numbers in this HTML DO have trailing zeros then it is problem with Excel. But if you will see numbers WITHOUT trailing zeros then there is a problem with output (code in your page/handler)

R
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now