473,378 Members | 1,138 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,378 software developers and data experts.

arithmetic overflow

I have the following that works:

public static void GetValueFromDbObject(object dbObjectValue, ref decimal
destination)
{
destination = 2323;
return;
}

This gives me an arithmetic overflow:

public static void GetValueFromDbObject(object dbObjectValue, ref decimal
destination)
{
destination = decimal.MaxValue;
return;
}

How can that be? I thought that decimal.MaxValue is the maximum value you
can have.

Thanks,

Tom
Nov 17 '05 #1
3 1644
"tshad" <ts**********@ftsolutions.com> wrote:
This gives me an arithmetic overflow:
public static void GetValueFromDbObject(
object dbObjectValue, ref decimal destination)
{
destination = decimal.MaxValue;
return;
}


It works fine here (.NET Framework 1.1.4322 SP1).

Are you absolutely sure that *this* is causing the overflow, and not
anything else in your program?

P.
Nov 17 '05 #2
"Paul E Collins" <fi******************@CL4.org> wrote in message
news:dj**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
"tshad" <ts**********@ftsolutions.com> wrote:
This gives me an arithmetic overflow:
public static void GetValueFromDbObject(
object dbObjectValue, ref decimal destination)
{
destination = decimal.MaxValue;
return;
}
It works fine here (.NET Framework 1.1.4322 SP1).

Are you absolutely sure that *this* is causing the overflow, and not
anything else in your program?


It is something else.

Took me a while to find it and am trying to work out why.

I am writing this to a money field in Sql Server.

I assume that decimal is larger that Money (even though I read that they are
equivelant) and that when dealing with Money fields, you should use decimal
in C#. But that doesn't mean the max's are the same.

Tom
P.

Nov 17 '05 #3
"tshad" <ts**********@ftsolutions.com> wrote:
I assume that decimal is larger that Money (even though
I read that they are equivelant) and that when dealing with
Money fields, you should use decimal in C#.


No. Use SqlMoney from System.Data.SqlTypes.

P.
Nov 17 '05 #4

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

Similar topics

3
by: Karthik | last post by:
Hi, I am writing this application that needs a lot of arithmetic calculations. I was wondering if C++ language specifies any way of detecting arithmetic overflows. Let us consider the following...
5
by: Fraser Ross | last post by:
void f(unsigned int const x) { }; int main(int argc, char* argv){ //unsigned short a=0xFFFF; enum { a=0xFFFF }; f(a*0x10000+0xFFFF); return 0; } I get an arithmetic overflow when using a as...
10
by: Massimiliano Alberti | last post by:
Are there rules on how should the C behave with the arithmetic operations? Are the overflows always ignored? And are they simply truncated? (if I have a 16-bits unsigned short ints unsigned short...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
4
by: glenn | last post by:
I have a COM Server I've written in C#. I have a client app I've written in Delphi that is calling the C# COM Server. However, one of the functions in the COM Server creates a form and during the...
4
by: Tom | last post by:
I have a VB.NET framework 1.1 application that I am installing on my user's workstation. It works fine on EVERY machine except for one - on this one machine it generates a 'Overflow or underflow in...
3
by: Paul Cheetham | last post by:
Hi, I am developing a program that is doinbg time calculations using Ticks. Below is a piece of code that is causing an arithmetic overflow exception - the single line inside the try statement....
9
by: Mike Aubury | last post by:
Is there any standard (or even non-standard) way to detect limit overflow in arithmetic in C ? eg. /* assuming 4 byte ints.. */ int a=2147483647; int b=2147483647; int c;
1
by: thebigsquid | last post by:
hi, its me again, so this software obviously has serious problems. now i'm getting this error message when i try to access any of it! any ideas much appreciated thanks the big squid An...
10
by: Why Tea | last post by:
I understood that the CPU registers determine the size of the machine. But what is the correct way to code an arithmetic operation to avoid wrap-around when the code is to be run on both 32-bit and...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.