[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Working with decimals in C#

Posted on 2004-10-07
1
Medium Priority
?
1,816 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 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

656 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