Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
242 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 400 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 1600 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

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

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video teaches users how to migrate an existing Wordpress website to a new domain.
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.
Suggested Courses

916 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