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
235 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

809 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