By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,280 Members | 2,227 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,280 IT Pros & Developers. It's quick & easy.

Decimal numbers with possible null values?

P: n/a
I searched for previous answers on this, but couldn't find something
fitting. I need advice on how to store decimal numbers with possible
null values in memory. The numbers may be negative, so storing null
values as -1 doesn't work. The numbers are amounts of money, so
decimal is the best datatype, except that it can't store null values.

The best idea so far is to make an object of each number and have it
store either a decimal or null. It's not pretty, but I think it would
work. Can anyone find something more straightforward?

Thanks,

Gustaf

Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I suppose you could use a string, then have some conversion to decimal after
you've confirmed the string is not null. You then also have the case where
the value is null.

"Gustaf Liljegren" <gu**************@bredband.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I searched for previous answers on this, but couldn't find something
fitting. I need advice on how to store decimal numbers with possible
null values in memory. The numbers may be negative, so storing null
values as -1 doesn't work. The numbers are amounts of money, so
decimal is the best datatype, except that it can't store null values.

The best idea so far is to make an object of each number and have it
store either a decimal or null. It's not pretty, but I think it would
work. Can anyone find something more straightforward?

Thanks,

Gustaf

Nov 16 '05 #2

P: n/a
Gustaf,

If you can use the beta of .NET 2.0, then I would look into using the
Nullable generic type. If you can not use that, then I would recommend
using the SqlDecimal class in the System.Data.SqlTypes namespace. It will
have pretty much what you want (IsNull or HasValue properties), and you
should be able to swap them out with little problems when you move to .NET
2.0.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Gustaf Liljegren" <gu**************@bredband.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I searched for previous answers on this, but couldn't find something
fitting. I need advice on how to store decimal numbers with possible
null values in memory. The numbers may be negative, so storing null
values as -1 doesn't work. The numbers are amounts of money, so
decimal is the best datatype, except that it can't store null values.

The best idea so far is to make an object of each number and have it
store either a decimal or null. It's not pretty, but I think it would
work. Can anyone find something more straightforward?

Thanks,

Gustaf

Nov 16 '05 #3

P: n/a
Gustaf Liljegren <gu**************@bredband.net> wrote:
I searched for previous answers on this, but couldn't find something
fitting. I need advice on how to store decimal numbers with possible
null values in memory. The numbers may be negative, so storing null
values as -1 doesn't work. The numbers are amounts of money, so
decimal is the best datatype, except that it can't store null values.

The best idea so far is to make an object of each number and have it
store either a decimal or null. It's not pretty, but I think it would
work. Can anyone find something more straightforward?


Along with the other options presented by other posters, have you
considered using a "special value" which will never actually come up?
For instance, Decimal.MaxValue? If any *real* data ever came close to
that, you'd have to worry about overflow anyway.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.