• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

Convert to decimal problems

Hi
can anyone help with this problem, I'm trying to add a value to a textbox but cannot seem to get the datareader to convert the value into a decimal.

tbBudget.Text = RdrGetCustomerDetails["intBudget"].ToString("c");
I keep receiving the error: No overload for method 'ToString' takes '1' arguments

Any help would be appreciated on this
Caz
0
BeginningWebDesign
Asked:
BeginningWebDesign
  • 2
  • 2
1 Solution
 
mikkelpCommented:

Hi Caz

that's because ToString() doesn't take any argument.

you could probably do this:

tbBudget.Text = RdrGetCustomerDetails["intBudget"].ToString();

or if you want the decimal as a decimal.

// int index = 42 // your decimal value's column-index
tbBudget.Text = RdrGetCustomerDetails.GetDecimal(index).ToString();


mikkel
0
 
BeginningWebDesignAuthor Commented:
Hi mikkel

The code below works, but how can I display only 2 decimal places after the . i.e 20.00 as it currently displays 20.0000
tbBudget.Text = RdrGetCustomerDetails["intBudget"].ToString();

Caz
0
 
mikkelpCommented:
ahh. I get it, sorry for my being slow in the uptake..

one way:

tbBudget.Text = RdrGetCustomerDetails.GetDecimal(index).ToString("c");

another

tbBudget.Text = string.Format("{0:c}", RdrGetCustomerDetails.GetDecimal(index));

the reason why your RdrGetCustomerDetails["intBudget"].ToString("c") didn't work, was because RdrGetCustomerDetails["intBudget"] isn't of type "decimal". You could fix it like this: ((decimal)RdrGetCustomerDetails["intBudget"]).ToString("c");

Mikkel
0
 
Diego PazosCommented:
Try doing:

tbBudget.Text = Convert.ToDecimal(RdrGetCustomerDetails["intBudget"]).ToString("0.00");
0
 
BeginningWebDesignAuthor Commented:
Thanks mikkelp
Caz
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now