How to convert correctly

  • Thread starter Thread starter Marc Robitaille
  • Start date Start date
M

Marc Robitaille

Hello group,

I have a little problem and I don't know how to solve it. I use Textbox to
let my user type the price of their products. The Textbox only accept number
and the decimal separator. When they confirm the price I do a
Convert.ToDecimal to store the value in the database. The problem is when
they enter a really big number in the textbox. The convert function faile.
My questions are:
What is the best thing to do in that kind of situation? Is the Try Catch is
the only way to solve this kind of error? I don't what to use the Try Catch
because it slow down the program.

Thank you very much for your help :-)
Marc R.
 
What is the best thing to do in that kind of situation? Is the Try
Catch is the only way to solve this kind of error? I don't what to use
the Try Catch because it slow down the program.

I would use a try/catch to catch a conversion error.
 
Marc Robitaille said:
Hello group,

I have a little problem and I don't know how to solve it. I use Textbox to
let my user type the price of their products. The Textbox only accept
number and the decimal separator. When they confirm the price I do a
Convert.ToDecimal to store the value in the database. The problem is when
they enter a really big number in the textbox. The convert function faile.
My questions are:
What is the best thing to do in that kind of situation? Is the Try Catch
is the only way to solve this kind of error? I don't what to use the Try
Catch because it slow down the program.

Thank you very much for your help :-)
Marc R.


It shouldnt slow it down too much if they dont type in unreasonably large
numbers.

use Try/Catch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top