Solved

Working with decimals in C#

Posted on 2004-10-07
1
1,804 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
davidastle earned 50 total points
ID: 12252938
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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