Skip to content

Format Double

Alex Leon

Asked Jun 30, 2009, 10:24 AM EDT3 answers
Share
LinkedInX
Needed some help with the following code. I am trying to format the result to a decimal ##0.00  this is the first time I am trying to work with C# and need some help. Thank you
I have tried to modify the code and I just can't get this correct.
 
            if (this.DataSource.BalanceSpecified) {
                     
                string formattedValue = this.DataSource.Format(TblPaymentRequestTable.Balance);
                formattedValue = HttpUtility.HtmlEncode(formattedValue);
                if(formattedValue != null){
                   
                    int maxLength = formattedValue.Length;
                    if (maxLength > (int)(100.00)){
                        maxLength = (int)(100.00);
                       
                    }
                    if (maxLength == (int)(100.00)) {
                        formattedValue = NetUtils.EncodeStringForHtmlDisplay(formattedValue.Substring(0,maxLength));
                        formattedValue = formattedValue + "...";
                    }
                                      
                }                             
                   
                this.Balance.Text = formattedValue;
             
              
            } else { 
                this.Balance.Text = TblPaymentRequestTable.Balance.Format(TblPaymentRequestTable.Balance.DefaultValue);
                           
            }
 

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Niradhip Chakraborty
    0
    Try This:
    Convert.ToDouble(formattedValue).ToString("C");
    0
  • 0
    Can you show me your example but include my code?
     
    Thank you
    0
  • Niradhip Chakraborty
    0

    if (this.DataSource.BalanceSpecified)

    {
                         
         string formattedValue = this.DataSource.Format(TblPaymentRequestTable.Balance);
         formattedValue = HttpUtility.HtmlEncode(formattedValue);
          if(formattedValue != null)

          {
               int maxLength = formattedValue.Length;
                if (maxLength > (int)(100.00))

                {
                     maxLength = (int)(100.00);
                 }
                  if (maxLength == (int)(100.00))

    {
                            formattedValue =                                     NetUtils.EncodeStringForHtmlDisplay(formattedValue.Substring(0,maxLength));
        formattedValue = formattedValue + "...";
      }
                                          
     }                             
                       
         this.Balance.Text =
    Convert.ToDouble(formattedValue).ToString("C");

    } else

    { 
                    this.Balance.Text = TblPaymentRequestTable.Balance.Format(TblPaymentRequestTable.Balance.DefaultValue);
                               
       }
     

    0