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
233 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
ID: 22670305
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
ID: 22670566
if you want to convert 1.1 to 1.10 then use
(1.1).ToString("0.00");
0
 

Author Comment

by:toshi_
ID: 22676695
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
ID: 22677093
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio editor? 1 38
Authentication of Web Services 3 54
I need help embedding Base64 Images using VB.Net - When image is a .jpg 2 43
Variable Event ? 3 23
Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

863 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

22 Experts available now in Live!

Get 1:1 Help Now