Solved

C# - reading 2 digits to right of decimal on type double var

Posted on 2006-11-03
3
871 Views
Last Modified: 2006-11-20
Anyone know a simple way to write code for reading the 2 digits to the right of decimal of a variable of type double..  For instance, let's say we want to accept all numbers, i.e...

54.28
54.31
54.88
55.02

but we don't want to accept any numbers that have the 2 digits to the right of the decimal ==     .00   or    .50      as follows...

54.00
54.50
55.00
55.50

etc...

so in pseudocode..   it may look something like this..

If ( last 2 digits == .50  ||  last 2 digits == .00 )
{
    return;
}


Lot of points here for the right answer!  Thanks all.

0
Comment
Question by:lblinc
3 Comments
 
LVL 13

Accepted Solution

by:
joechina earned 400 total points
ID: 17867088
int i = (int)(yourdouble * 100) % 100;
if (i == 50 || i == 0)
{
return;
}
0
 
LVL 4

Assisted Solution

by:satish_nagdev
satish_nagdev earned 100 total points
ID: 17879286
hi ,
does following solves your problem
                double[] dds = {54.28, 54.31, 54.88, 55.02, 55.60, 55.30, 59.60};
      for(int cnt = 0; cnt < dds.Length; cnt++)
      {
            if((int)Math.Ceiling(dds[cnt]) != (int)Math.Round(dds[cnt]))
            {
                  MessageBox.Show("ding ding ding");
            }
      }

regards,
satish.
0
 

Author Comment

by:lblinc
ID: 17984970
Thanks to both!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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 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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 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