Solved

Working with decimals in C#

Posted on 2004-10-07
1
1,796 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
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Server Error 11 58
rest webservice call over https via c# 6 37
Network monitoring with information includes process path and destination IP 2 50
SqlDataBase 7 46
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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