Hi,
I wonder whether anyone could help me to do a maths calculation?
I have three boxes which take numeric values
double PPrice = Convert.ToDouble(txtPurchasePrice.Text);
double BCost = Convert.ToDouble(txtBuildCost.Text);
double Morg = Convert.ToDouble(txtMortgage.Text);
As each box has lostfocus/validating, the amount to be placed in a textbox
adding to it the
previous amount, so giving a running total.
I have tried to add (PPrice + BCost-Morg); but keep getting errors.
I do, however, get it to work when I use " StreamWriter" and write to a text
file, but it
will not give me a total on the screen.
I would be most appreciative if you would be good enough to show me how this
can be
done.
Harry 9 1951
Perhaps you could post the code that you use to display the total "on the
screen" as well as what the errors are. It would make it much easier to
help you.
DalePres
MCAD, MCDBA, MCSE
"Harry" <ob*****@absamail.co.za> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... Hi,
I wonder whether anyone could help me to do a maths calculation? I have three boxes which take numeric values
double PPrice = Convert.ToDouble(txtPurchasePrice.Text); double BCost = Convert.ToDouble(txtBuildCost.Text); double Morg = Convert.ToDouble(txtMortgage.Text);
As each box has lostfocus/validating, the amount to be placed in a textbox adding to it the
previous amount, so giving a running total. I have tried to add (PPrice + BCost-Morg); but keep getting errors. I do, however, get it to work when I use " StreamWriter" and write to a text file, but it
will not give me a total on the screen.
I would be most appreciative if you would be good enough to show me how this can be
done.
Harry
why are you converting the number to a double?
Double-precision numbers are used for scientific calculations, not for
monetary calculations. You are LIKELY to get errors.
Use Decimal numbers.
Also, to repeat a previous responder: post your code and describe the errors
you are getting.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Harry" <ob*****@absamail.co.za> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... Hi,
I wonder whether anyone could help me to do a maths calculation? I have three boxes which take numeric values
double PPrice = Convert.ToDouble(txtPurchasePrice.Text); double BCost = Convert.ToDouble(txtBuildCost.Text); double Morg = Convert.ToDouble(txtMortgage.Text);
As each box has lostfocus/validating, the amount to be placed in a textbox adding to it the
previous amount, so giving a running total. I have tried to add (PPrice + BCost-Morg); but keep getting errors. I do, however, get it to work when I use " StreamWriter" and write to a text file, but it
will not give me a total on the screen.
I would be most appreciative if you would be good enough to show me how this can be
done.
Harry
What errors are you getting? And where? In the conversion, or in the
addition? Is it really an error (as in, an exception) or is it just an
unexpected result without an actual exception being thrown? Please provide
code and indicate exactly where the "error" occurs.
I agree with another respondent -- use decimal rather than double. This
will take care of virtually all rounding errors you might encounter. In
fact I consider floating point formats to be, for the most part, evil.
Decimal is slower and takes up more memory but usually not enough to matter
with modern hardware and real world scenarios.
--Bob
"Harry" <ob*****@absamail.co.za> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... Hi,
I wonder whether anyone could help me to do a maths calculation? I have three boxes which take numeric values
double PPrice = Convert.ToDouble(txtPurchasePrice.Text); double BCost = Convert.ToDouble(txtBuildCost.Text); double Morg = Convert.ToDouble(txtMortgage.Text);
As each box has lostfocus/validating, the amount to be placed in a textbox adding to it the
previous amount, so giving a running total. I have tried to add (PPrice + BCost-Morg); but keep getting errors. I do, however, get it to work when I use " StreamWriter" and write to a text file, but it
will not give me a total on the screen.
I would be most appreciative if you would be good enough to show me how this can be
done.
Harry
Bob Grommes <bo*@bobgrommes.com> wrote: What errors are you getting? And where? In the conversion, or in the addition? Is it really an error (as in, an exception) or is it just an unexpected result without an actual exception being thrown? Please provide code and indicate exactly where the "error" occurs.
I agree with another respondent -- use decimal rather than double.
Agreed.
This will take care of virtually all rounding errors you might encounter.
I think that may be overstating a bit. As soon as you do any division,
for instance, you're likely to get rounding errors. Whether or not
they're significant is a different matter - applications like this
should have well-defined error tolerances etc.
In fact I consider floating point formats to be, for the most part, evil.
And yet Decimal itself is a floating point type :)
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Thank you one and all I have solved the problem :-)
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Bob Grommes <bo*@bobgrommes.com> wrote: What errors are you getting? And where? In the conversion, or in the addition? Is it really an error (as in, an exception) or is it just an unexpected result without an actual exception being thrown? Please provide code and indicate exactly where the "error" occurs.
I agree with another respondent -- use decimal rather than double.
Agreed.
This will take care of virtually all rounding errors you might encounter.
I think that may be overstating a bit. As soon as you do any division, for instance, you're likely to get rounding errors. Whether or not they're significant is a different matter - applications like this should have well-defined error tolerances etc.
In fact I consider floating point formats to be, for the most part, evil.
And yet Decimal itself is a floating point type :)
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Just for the edification of those who put in time and effort considering
your question, you might want to provide some details of what was wrong and
how you solved it.
DalePres
"Harry" <ob*****@absamail.co.za> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... Thank you one and all I have solved the problem :-) "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om... Bob Grommes <bo*@bobgrommes.com> wrote: What errors are you getting? And where? In the conversion, or in the addition? Is it really an error (as in, an exception) or is it just an unexpected result without an actual exception being thrown? Please provide code and indicate exactly where the "error" occurs.
I agree with another respondent -- use decimal rather than double.
Agreed.
This will take care of virtually all rounding errors you might encounter.
I think that may be overstating a bit. As soon as you do any division, for instance, you're likely to get rounding errors. Whether or not they're significant is a different matter - applications like this should have well-defined error tolerances etc.
In fact I consider floating point formats to be, for the most part, evil.
And yet Decimal itself is a floating point type :)
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
It was such a minor detail, that I am embarrassed to tell you how simple it
was to correct it.
It was a minor oversight and I very much appreciate the effort that was put
in.
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:ed**************@tk2msftngp13.phx.gbl... Just for the edification of those who put in time and effort considering your question, you might want to provide some details of what was wrong and how you solved it.
DalePres
"Harry" <ob*****@absamail.co.za> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl... Thank you one and all I have solved the problem :-) "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om... Bob Grommes <bo*@bobgrommes.com> wrote: What errors are you getting? And where? In the conversion, or in the addition? Is it really an error (as in, an exception) or is it just an unexpected result without an actual exception being thrown? Please provide code and indicate exactly where the "error" occurs.
I agree with another respondent -- use decimal rather than double.
Agreed.
This will take care of virtually all rounding errors you might encounter.
I think that may be overstating a bit. As soon as you do any division, for instance, you're likely to get rounding errors. Whether or not they're significant is a different matter - applications like this should have well-defined error tolerances etc.
In fact I consider floating point formats to be, for the most part, evil.
And yet Decimal itself is a floating point type :)
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Bob Grommes <bo*@bobgrommes.com> wrote: This will take care of virtually all rounding errors you might encounter.
I think that may be overstating a bit. As soon as you do any division, for instance, you're likely to get rounding errors. Whether or not they're significant is a different matter - applications like this should have well-defined error tolerances etc.
I am talking about insiduous and counterintuitive rounding errors. In
real-world business applications I have yet to have division or
multiplication between two decimal numbers produce anything other than what
one would expect. In fact I consider floating point formats to be, for the most part, evil.
And yet Decimal itself is a floating point type :)
Okay, ya got me there, Jon. But is System.Decimal not just at heart an
implementation of good old BCD? It is capable of precisely representing any
number that it can express, whereas an 8-byte float / real cannot always
pull that off (for a given value of "always" ;-)
--Bob
Bob Grommes <bo*@bobgrommes.com> wrote: "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om...
Bob Grommes <bo*@bobgrommes.com> wrote: This will take care of virtually all rounding errors you might encounter. I think that may be overstating a bit. As soon as you do any division, for instance, you're likely to get rounding errors. Whether or not they're significant is a different matter - applications like this should have well-defined error tolerances etc.
I am talking about insiduous and counterintuitive rounding errors. In real-world business applications I have yet to have division or multiplication between two decimal numbers produce anything other than what one would expect.
Multiplication should be fine until you start getting towards the edge
of the scale or precision. Division will entirely depend on the app.
Any time you take the average of some numbers, you leave yourself open
to rounding errors. Whether those are *significant* rounding errors or
not is a slightly different matter.
Also don't forget that not all apps are business apps - there are
plenty of scientific apps as well, and they're much more likely to rely
on division. In fact I consider floating point formats to be, for the most part, evil.
And yet Decimal itself is a floating point type :)
Okay, ya got me there, Jon. But is System.Decimal not just at heart an implementation of good old BCD?
I think it's closer to binary floating point than BCD, to be honest,
but both are fundamentally just an integer along with something that
says where the point goes.
It is capable of precisely representing any number that it can express, whereas an 8-byte float / real cannot always pull that off (for a given value of "always" ;-)
No, binary floating point also precisely represents any number it can
express. It also "roughly" represents numbers near to those numbers -
just as decimal does.
The difference is really just a human bias towards thinking of decimal
representations as more "real" than binary representations. (There are
also differences in the sort of "density of precision" in the way that
the IEEE representations are designed to cope with much larger and
smaller numbers than decimal, by losing a lot of precision at the large
end. That's a slightly different matter though.)
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David Morris |
last post by:
OK, this is for you experienced Java programmers out there.
I have a string that contains the following value:
"myValue += 5"
I need, in Java, to be able to evaluate this expression.
...
|
by: faheem via .NET 247 |
last post by:
From: faheem wattoo
I am have the same as above listed problemof System.ArithmaticOperation from last 3 months instead of repateding 5 freshinstallation.some times it runs well on the first...
|
by: junky_fellow |
last post by:
Can I subtract two pointers of same type that are pointing to the two
different location of memory allocated by malloc.
eg.
#include <stdlib.h>
int main(void)
{
unsigned char *c_ptr;...
|
by: Daz |
last post by:
Hi everyone.
I am a little confused and frustrated as to how the maximum lengths for
integers and floating point numbers came about, and whilst you
shouldn't need a number bigger than...
|
by: sapnakiran |
last post by:
Can u tell me how can we build up arithmatic operation without using arithmatic operator
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |