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

Casting problem on decimal nullable

Hi all,
I have this snippet that don't compile:

Math.Ceiling(-voceValue.Value - 0.5M);

because the field Value of the class voceValue is decimal nullable.

How can I solve?

Thanks a lot.
--
Luigi

Nov 5 '08 #1
5 4744
Well, you need to know what you want to do if it is null. You can
check first with HasValue, or use can use .Value (i.e. .Value.Value)
or a cast to assert that it is non-null, or you can
use .GetValueOrDefault [using zero or your own default].

Marc
http://marcgravell.blogspot.com/
Nov 5 '08 #2
"Marc Gravell" wrote:
Well, you need to know what you want to do if it is null. You can
check first with HasValue, or use can use .Value (i.e. .Value.Value)
or a cast to assert that it is non-null, or you can
use .GetValueOrDefault [using zero or your own default].
Hi Marc,
GetValueOrDefault is only for C# 3.0?
Actually I'm using C# 2.0.
I'm trying with .HasValue.

Luigi
Nov 5 '08 #3
On Nov 5, 10:15*am, Luigi <ciupazNoSpamGra...@inwind.itwrote:
"Marc Gravell" wrote:
Well, you need to know what you want to do if it is null. You can
check first with HasValue, or use can use .Value (i.e. .Value.Value)
or a cast to assert that it is non-null, or you can
use .GetValueOrDefault [using zero or your own default].

GetValueOrDefault is only for C# 3.0?
Actually I'm using C# 2.0.
I'm trying with .HasValue.
GetValueOrDefault has been in System.Nullable<Tsince .NET 2.0. (It's
a framework thing, not a language thing.)

Jon
Nov 5 '08 #4
GetValueOrDefault is only for C# 3.0?
Actually I'm using C# 2.0.
GetValueOrDefault is part or Nullable<Twhich ships with .NET 2.0

http://msdn.microsoft.com/en-us/libr...cw(VS.80).aspx

Marc
http://marcgravell.blogspot.com/
Nov 5 '08 #5
"Marc Gravell" wrote:
GetValueOrDefault is only for C# 3.0?
Actually I'm using C# 2.0.

GetValueOrDefault is part or Nullable<Twhich ships with .NET 2.0

http://msdn.microsoft.com/en-us/libr...cw(VS.80).aspx
Very weel, thank you Marc and Jon.

Luigi
Nov 5 '08 #6

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

Similar topics

5
by: Bryce | last post by:
First off, I hope I am posting this in the correct place Convert.ToDecimal() is throwing a FormatException, as is Decimal.Parse() if I send in the string "000063.27" or "+000063.27". I tried...
11
by: Steven Bartley | last post by:
Error Message on execution: An unhandled exception of type 'System.InvalidCastException' occurred in CastObjectToDecimal.exe Additional information: Specified cast is not valid. The code in...
4
by: Mark | last post by:
We have a SQL Server table with a decimal column that is not required. We're building a .NET application for data entry. If the value is optional, but a decimal is strongly typed in C# and cannot...
3
by: Steve Teeples | last post by:
I have a method that passes in two string objects (both numerical numbers) and a string identifying their type. public bool DoCompare(string num1, string num2, string theirType) { System.Type...
10
by: Tyler Durden | last post by:
Hi, I have this annoying problem with a cast failing from a DAL that was created in 1.1 that I have included in a 2.0 app. Every stored proc in our system uses an integer parameter to return...
5
by: Franky | last post by:
Can a Decimal variable be set to "Not a Number" I've been looking in the help and can't find any reference to that. Thanks in advance
3
by: newbtemple | last post by:
Hey all, having some trouble with casting values inputed into a text box into double. In particular, I'm having trouble with the decimal. It's ok if someone puts in a number with a decimal when...
4
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, I have an expression like this: decimal? ValoreComplessivoNettoDelfondoValue = (totaleAttivitaValue.HasValue || totalePassivitaValue.HasValue) ? ((totaleAttivitaValue ?? 0) -...
2
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all how can I write a method that returns me true if is possible to cast an object to decimal nullable and false if not? Like public bool CanConvert(object obj) { return true if obj is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.