1. ## Calculator Help !

Hi there everyone,

I have made a simple calculator (even though there are a hell lot of validations !!), but i'm basically stuck at two things..

1. The calculator should validate / normalize any inputs such as "0.500" or "0.5000" as "0.5", "0.101010" as "0.10101 (just remove the last zero)"

2. I have tried declaring the values and operations as Long / Double. is that good ? and when the calculations exceed the limit, it bypasses the Maxlength property of Textbox, returns an error "Stack Overflow exception, Make sure you are not Dividing by Zero."
Any ideas ??

P.S: The textbox is not multiline.

2. ## Re: Calculator Help !

1. Convert the String to a Decimal and then convert that back to a String.

2. Use Decimal, which is slower but less subject to round-off errors. As for the exception, you'd have to look at the actual code and the actual data being executed at the time.

You may like to follow the CodeBank link in my signature and check out my thread for a Numeric Text Box. Feel free to use it as is or to take bits of code from it as required.

3. ## Re: Calculator Help !

The conversion to decimal fixed the first issue, thanks very much..
but for the 2nd one..I'll elaborate...

When i perform calculations like 9999999999999*999999999999

The result is a scientific notation - a large number like 9999999999999998E + 2, the problem is it CROSSES THE MAXLENGTH PROPERTY OF THE TEXTBOX, goes beyond the textbox size, and crashes the application. Any ideas will be appreciated. Thank you.

4. ## Re: Calculator Help !

Originally Posted by niksh19
but for the 2nd one..I'll elaborate...

When i perform calculations like 9999999999999*999999999999

The result is a scientific notation - a large number like 9999999999999998E + 2, the problem is it CROSSES THE MAXLENGTH PROPERTY OF THE TEXTBOX, goes beyond the textbox size, and crashes the application. Any ideas will be appreciated. Thank you.
There's no magic here. If the String is too long for the TextBox then it's too long. Either increase the MaxLength or else don't display the value.

5. ## Re: Calculator Help !

I have also tried suppressing the exception by using try..catch...finally but that doesn't catch the exception.

i was just hoping to catch the exception, display a label saying "out of bounds" and then reset the textbox value to "0".
Can i achieve this? If yes. How ?

6. ## Re: Calculator Help !

Just like your other thread, you're giving us very little information and expecting us to somehow magically know the rest. Your code is apparently wrong but we haven't seen your code so we can't possibly tell you what's wrong with it.

That said, why would you have to catch an exception anyway? You know how long your String is and you know the MaxLength of your TextBox so why would you even try to display a value that you know is too big?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured