Cookieman
BSOD Kernel Dump Senior Analyst
Hi All :wave:
So far all is going well in my little program! One thing I am stuck on however is decimal places without any rounding. Below is a screenshot of my Application Console program (as yet incomplete!) with realistic values that I will be using as input. One very important aspect of this program is the average which is shown under Calculation of Control Limits. In this instance is it presently at 0.08875...blah blah blah.
What I am interested in, is the first two numbers after the decimal place, in this case it is 08. This number is then tripled to create what we call the Cpk Division Factor. If we take 0.08 and times it by 3 we get an answer of 0.24, however, under the current circumstances, the program is multiplying the whole of the number and returning an answer of 0.266272..... and so on which gives me a discrepancy of 0.02 after the first two decimal places which is something I do not want to happen.
What I need to know is simply how to get c# to read just the first two places after the point and then multiply it. I have included my code for the program below (although it may seem messy and full of holes (something to refine later) to the experts here!)
Thanks.
So far all is going well in my little program! One thing I am stuck on however is decimal places without any rounding. Below is a screenshot of my Application Console program (as yet incomplete!) with realistic values that I will be using as input. One very important aspect of this program is the average which is shown under Calculation of Control Limits. In this instance is it presently at 0.08875...blah blah blah.
What I am interested in, is the first two numbers after the decimal place, in this case it is 08. This number is then tripled to create what we call the Cpk Division Factor. If we take 0.08 and times it by 3 we get an answer of 0.24, however, under the current circumstances, the program is multiplying the whole of the number and returning an answer of 0.266272..... and so on which gives me a discrepancy of 0.02 after the first two decimal places which is something I do not want to happen.
What I need to know is simply how to get c# to read just the first two places after the point and then multiply it. I have included my code for the program below (although it may seem messy and full of holes (something to refine later) to the experts here!)
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Averages
{
class Program
{
static void Main(string[] args)
{
// Welcome to my first program! - Averages
Console.WriteLine("****************************************");
Console.WriteLine("** **");
Console.WriteLine("** Written in C Sharp by S.Percival **");
Console.WriteLine("** **");
Console.WriteLine("** 04/11/2012 **");
Console.WriteLine("** **");
Console.WriteLine("****************************************");
Console.WriteLine(" ");
// Set variables
double xr, a2, d4;
xr=1.69;
a2=1.02;
d4=2.57;
// Floating variables
double nom, est, avr, tol, a, b, c, d, e, f, g, h, left, right, value;
// Nominal Length
Console.WriteLine("Enter Product Nominal");
nom = Convert.ToSingle(Console.ReadLine());
// Actual Length
Console.WriteLine("Enter Actual Length");
est = Convert.ToSingle(Console.ReadLine());
// Average Range
Console.WriteLine("Enter Average Range");
avr = Convert.ToSingle(Console.ReadLine());
// Tolerance
Console.WriteLine("Enter Tolerance");
tol = Convert.ToSingle(Console.ReadLine());
// Mathematics
a = nom + tol;
b = nom - tol;
c = d4 * avr;
d = avr / xr;
e = d * 3;
f = d * 4;
g = a - est;
h = est - b;
// Output to Screen
Console.WriteLine(" ");
Console.WriteLine("Product Information.......");
Console.WriteLine(" ");
Console.WriteLine("Upper Limit (UCLx) = " + a);
Console.WriteLine("Lower Limit (LCLx) = " + b);
Console.WriteLine("Lower Range (LCLr) = " + c);
Console.WriteLine(" ");
Console.WriteLine("Calculation of Control Limits.......");
Console.WriteLine(" ");
Console.WriteLine("Average = " + d);
Console.WriteLine("CPK Division Factor = " + e);
Console.WriteLine("Estimate of Capability " + f);
Console.WriteLine(" ");
Console.WriteLine("Cpk Values.......");
Console.WriteLine(" ");
Console.WriteLine("Left Cpk = " +g);
Console.WriteLine("Right Cpk = " +h);
Console.WriteLine(" ");
Console.WriteLine("Press any key to exit");
Console.ReadLine();
}
}
}
Thanks.