473,549 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Decimal numbers with possible null values?

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
3 14377
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******** ********@TK2MSF TNGP09.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
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.Sql Types 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.co m

"Gustaf Liljegren" <gu************ **@bredband.net > wrote in message
news:%2******** ********@TK2MSF TNGP09.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
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.MaxValu e? If any *real* data ever came close to
that, you'd have to worry about overflow anyway.

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

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

Similar topics

21
4498
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
17
6115
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to...
687
23002
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't believe that. in pieces of the application where speed really matters you can still use "normal" functions or even static methods which is...
10
8111
by: Paul Sullivan | last post by:
decimal d; d = 1.1M OR d= (decimal) 1.1 Discussioon
28
5836
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is...
1
3437
by: Twanne | last post by:
Hi, I've got some code in VBA where I calculate some numbers. Now some of them are large decimal numbers like -6,3216324E03. So in scientific notations. Now I need to add them to a table with an insert query. The query: db.Execute ("INSERT INTO tmpZscore (datum, leeftijd, lengte, ZscoreL, gewicht, ZscoreW, BMI, ZscoreB, IBW) VALUES('" &...
10
5306
by: Jason | last post by:
I'm making a program that will convert decimal inputs (in this case, in inches) and output a fractional answer. At the moment, I'm only able to output the fractional answer in three parts: A whole number text box, a numerator text box, and a denominator text box. I realize that this is probably the closest I'll get to having fractions...
4
4258
by: Astley Le Jasper | last post by:
I've been getting errors recently when using pysqlite. I've declared the table columns as real numbers to 2 decimal places (I'm dealing with money), but when doing division on two numbers that happen to have no decimal fractions, the results through pysqlite are coming through as integers. The funny thing is that when looking at the database...
0
28047
Frinavale
by: Frinavale | last post by:
Convert a Hex number into a decimal number and a decimal number to Hex number This is a very simple script that converts decimal numbers into hex values and hex values into decimal numbers. The example following this one demonstrates how to convert decimal numbers into binary values. A hex number is a string that contains numbers between...
0
7548
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7504
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7832
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6074
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3518
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3499
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1083
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
786
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.