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
236 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

      Install BugTracker on Windows 2008 server Step 1:  Install windows 2008 server 32 bit OS and configure IIS. Step 2:  Install SQL server ( SQL server 2005 or SQL server 2005 Express edition. The installer for 2008  version isn’t very f…
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
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.

749 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