Solved

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

Posted on 2006-11-03
3
878 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
[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
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

617 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