arithmetic overflow

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

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
 
tshad said:
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.
 
Paul E Collins said:
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
 
tshad said:
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.
 

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

Similar Threads

Comparison question 21
Class method doesn't seem to work 2
magic code.... 6
section three... correct? 3
so long? no other way? 11
How to use a property with ref accessor 2
waveInOpen 64-bit 0
Exceptions 1

Back
Top