473,382 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Negative Numbers?

Hello,

I have some textboxes that are doing addition:

Dim AString As Double
AString = Convert.ToDouble(TextBox1.Text) - Convert.To(DoubleTextBox2.Text)
TextBox3.Text = AString.ToString("#,##0.00;(#,##0.00);0.00")

When the result is negative it is displayed as "(46)" or whatever the value
is.
This makes it impossible to test for a negative number to make further
additions:

TextBox5.text = Convert.ToDouble(TextBox3.text) +
Convert.ToDouble(Textbox4.text)

Is there a work-around for this? I must have negative numbers that can be
added together.

Thanks,
Chuck
Jul 21 '05 #1
4 2115
It is displayed as "(46)" beacuse that is what your format specifier
("#,##0.00;(#,##0.00);0.00") is asking it to do for negative numbers.

Since the Convert.ToDouble function does not recognize this format, you
could check for the format you're looking for and change it appropriately:

For example:

string sText = TextBox3.Text
if (sText.StartsWith("("))
sText = "-" + sText.Remove("(").Remove(")")
end if

TextBox5.text = Convert.ToDouble(sText) + Convert.ToDouble(Textbox4.text)

Or, probably the better way to do this is to just use the result in AString
which is already a double and stores the value that you're looking for
anyways.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

"Charles A. Lackman" <Ch*****@CreateItSoftware.net> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
Hello,

I have some textboxes that are doing addition:

Dim AString As Double
AString = Convert.ToDouble(TextBox1.Text) - Convert.To(DoubleTextBox2.Text) TextBox3.Text = AString.ToString("#,##0.00;(#,##0.00);0.00")

When the result is negative it is displayed as "(46)" or whatever the value is.
This makes it impossible to test for a negative number to make further
additions:

TextBox5.text = Convert.ToDouble(TextBox3.text) +
Convert.ToDouble(Textbox4.text)

Is there a work-around for this? I must have negative numbers that can be added together.

Thanks,
Chuck

Jul 21 '05 #2
Hi Charles,

First of all, you're not doing addition; you're doing subtraction. Then,
when you fill textbox5, you'r trying to convert a string to a double. Try
debugging, set a few breakpoints, and follow the values.

HTH,

Bernie Yaeger

"Charles A. Lackman" <Ch*****@CreateItSoftware.net> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
Hello,

I have some textboxes that are doing addition:

Dim AString As Double
AString = Convert.ToDouble(TextBox1.Text) - Convert.To(DoubleTextBox2.Text) TextBox3.Text = AString.ToString("#,##0.00;(#,##0.00);0.00")

When the result is negative it is displayed as "(46)" or whatever the value is.
This makes it impossible to test for a negative number to make further
additions:

TextBox5.text = Convert.ToDouble(TextBox3.text) +
Convert.ToDouble(Textbox4.text)

Is there a work-around for this? I must have negative numbers that can be added together.

Thanks,
Chuck

Jul 21 '05 #3
Don't save the number in the text box, save it in a variable. Just use the
textbox for displaying the results.

--
Jonathan Allen
"Charles A. Lackman" <Ch*****@CreateItSoftware.net> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
Hello,

I have some textboxes that are doing addition:

Dim AString As Double
AString = Convert.ToDouble(TextBox1.Text) - Convert.To(DoubleTextBox2.Text) TextBox3.Text = AString.ToString("#,##0.00;(#,##0.00);0.00")

When the result is negative it is displayed as "(46)" or whatever the value is.
This makes it impossible to test for a negative number to make further
additions:

TextBox5.text = Convert.ToDouble(TextBox3.text) +
Convert.ToDouble(Textbox4.text)

Is there a work-around for this? I must have negative numbers that can be added together.

Thanks,
Chuck

Jul 21 '05 #4
Charles,
In addition to the other comments.

Use the Double.Parse overload (instead of Convert.ToDouble) that allows you
to specify the number style to use when converting, something like:
AString = Double.Parse(TextBox1.Text, NumberStyles.Currency) -
Double.Parse(DoubleTextBox2.Text, NumberStyles.Currency)
Read the help on NumberStyles enum to see what the various options allowed
are.

Hope this helps
Jay
"Charles A. Lackman" <Ch*****@CreateItSoftware.net> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl... Hello,

I have some textboxes that are doing addition:

Dim AString As Double
AString = Convert.ToDouble(TextBox1.Text) -
Convert.To(DoubleTextBox2.Text)
TextBox3.Text = AString.ToString("#,##0.00;(#,##0.00);0.00")

When the result is negative it is displayed as "(46)" or whatever the
value is.
This makes it impossible to test for a negative number to make further
additions:

TextBox5.text = Convert.ToDouble(TextBox3.text) +
Convert.ToDouble(Textbox4.text)

Is there a work-around for this? I must have negative numbers that can
be added together.

Thanks,
Chuck

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Imbaud Pierre | last post by:
integer division and modulo gives different results in c and python, when negative numbers are involved. take gdb as a widely available c interpreter print -2 /3 0 for c, -1 for python. more...
7
by: pj | last post by:
Why does M$ Query Analyzer display all numbers as positive, no matter whether they are truly positive or negative ? I am having to cast each column to varchar to find out if there are any...
5
by: Subrahmanyam Arya | last post by:
Hi Folks , I am trying to solve the problem of reading the numbers correctly from a serial line into an intel pentium processor machine . I am reading 1 byte and 2byte data both positive...
4
by: Charles A. Lackman | last post by:
Hello, I have some textboxes that are doing addition: Dim AString As Double AString = Convert.ToDouble(TextBox1.Text) - Convert.To(DoubleTextBox2.Text) TextBox3.Text =...
11
by: tlyczko | last post by:
Hello Rob B posted this wonderful code in another thread, http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/c84d8538025980dd/6ead9d5e61be85f0#6ead9d5e61be85f0 I could not...
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
11
by: drtimhill | last post by:
I'm just starting out on Python, and am stumped by what appears an oddity in the way negative indices are handled. For example, to get the last character in a string, I can enter "x". To get the...
39
by: Frederick Gotham | last post by:
I have a general idea about how negative number systems work, but I'd appreciate some clarification if anyone would be willing to help me. Let's assume we're working with an 8-Bit signed integer,...
20
by: Casey | last post by:
Is there an easy way to use getopt and still allow negative numbers as args? I can easily write a workaround (pre-process the tail end of the arguments, stripping off any non-options including...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.