Solved

Working with decimals in C#

Posted on 2004-10-07
1
1,792 Views
Last Modified: 2010-05-18
I have a few questions regarding variables of type decimal in C#:

   1. How do I define a decimal literal? (i.e. 100.1)
 
   2. How do I compare a decimal variable to a literal?

       if (value > 100.1)             ..........is giving me an error about using the > with a decimal
       {
       }

Thanks,
Rosanne
0
Comment
Question by:RosanneParnell
1 Comment
 
LVL 2

Accepted Solution

by:
davidastle earned 50 total points
Comment Utility
1.  Like the "f" suffix for floats, use the "M" suffix for decimals.
For example, 100.1M

2. You can compare a decimal variable to other decimal literals.
For example

if (value > 100.1M)
{
}

Alternatively, you can type cast 100.1 to a decimal (although this is not preferred, it is a good way to compare decimals to variables of other types).

if (value > (decimal)100.1)
{
}
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now