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);
}
Format Double
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Niradhip ChakrabortyRank #428 · 5.8K pointsPosted Jul 1, 2009, 1:57 AM EDT
Convert.ToDouble(formattedValue).ToString("C");
Alex Leon2 pointsPosted Jul 4, 2009, 12:07 PM EDT
Thank you
Niradhip ChakrabortyRank #428 · 5.8K pointsPosted Jul 5, 2009, 11:30 PM EDT
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);
}