I end up getting -0.944444444444444 when I want it to be -0.94 Assuming the entered temperature is 30.3 and clicking Fahrenheit to Celsius.  using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;  namespace TemperatureConverter {     public partial class FrmTemperature : Form     {         public FrmTemperature()         {             InitializeComponent();         }          private void btnCalcFahrenheit_Click(object sender, EventArgs e)         {             lblFahrenheit.Text = Convert.ToString(9.0/5.0 * Convert.ToDouble(txtTemperature.Text) + 32.0);         }          private void btnCalcCelsius_Click(object sender, EventArgs e)         {             lblCelsius.Text = Convert.ToString(5.0/9.0*(Convert.ToDouble(txtTemperature.Text) - 32.0));         }     } }
35731
I want to do this using the Math.Round function
119341
I'm pretty new to programming and made a few programs so far. I recently made a Calculator program and I hope you guys could tell me what I could do to improve. int firstNumber; string sign; int secondNumber; int answer;  Console.WriteLine(&quot;Input Number:&quot;); firstNumber = Convert.ToInt32(Console.ReadLine()); Console.Clear();  Console.WriteLine(&quot;Input Sign:&quot;); sign = Console.ReadLine(); Console.Clear();  Console.WriteLine(&quot;Input Second Number:&quot;); secondNumber = Convert.ToInt32(Console.ReadLine()); Console.Clear();  switch (sign) {     case &quot;+&quot;:         answer = firstNumber + secondNumber;         Console.WriteLine(answer);         Console.ReadKey();     break;     case &quot;-&quot;:         answer = firstNumber - secondNumber;         Console.WriteLine(answer);         Console.ReadKey();     break;     case &quot;*&quot;:         answer = firstNumber * secondNumber;         Console.WriteLine(answer);         Console.ReadKey();     break;     case &quot;/&quot;:         answer = firstNumber / secondNumber;         Console.WriteLine(answer);         Console.ReadKey();     break;     default:         Console.WriteLine(&quot;Invalid Input&quot;);     break; }
63628
Here's an example:  Double d = (1/3); System.out.println(d);   This returns 0, not 0.33333... as it should.  Does anyone know?
31758
The documentation for the  function states that you pass it a number, and the positions past the decimal to round. Thus it should do this:  n = 5.59 round(n, 1) # 5.6   But, in actuality, good old floating point weirdness creeps in and you get:  5.5999999999999996   For the purposes of UI, I need to display 5.6. I poked around the Internet and found some  that this is dependent on my implementation of Python. Unfortunately, this occurs on both my Windows dev machine and each Linux server I've tried. .  Short of creating my own round library, is there any way around this?
10332
I need to cast single figures (1 to 9) to (01 to 09). I can think of a way but its big and ugly and cumbersome. I'm sure there must be some concise way. Any Suggestions
32402
I have a C#/.Net job that imports data from Excel and then processes it. Our client drops off the files and we process them. I don't have any control over the original file.  I use the OleDb library to fill up a dataset. The file contains some numbers like 30829300, 30071500, etc... The data type for those columns is "Text".  Those numbers are converted to scientific notation when I import the data. Is there anyway to prevent this from happening?
102420
Something like:  0.1 0.23 0.999   How to pronounce them correctly in English?
5169
In my program I have one array with 25 double values 0.04 When I try to sum these values in a loop I get following results:  0.0 + 0.04 = 0.04 0.04 + 0.04 = 0.08 0.08 + 0.04 = 0.12 0.12 + 0.04 = 0.16 0.16 + 0.04 = 0.2 0.2 + 0.04 = 0.24000000000000002 0.24000000000000002 + 0.04 = 0.28 0.28 + 0.04 = 0.32 0.32 + 0.04 = 0.36 0.36 + 0.04 = 0.39999999999999997 0.39999999999999997 + 0.04 = 0.43999999999999995 0.43999999999999995 + 0.04 = 0.4799999999999999 0.4799999999999999 + 0.04 = 0.5199999999999999 0.5199999999999999 + 0.04 = 0.5599999999999999 0.5599999999999999 + 0.04 = 0.6 0.6 + 0.04 = 0.64 0.64 + 0.04 = 0.68 0.68 + 0.04 = 0.7200000000000001 0.7200000000000001 + 0.04 = 0.7600000000000001 0.7600000000000001 + 0.04 = 0.8000000000000002 0.8000000000000002 + 0.04 = 0.8400000000000002 0.8400000000000002 + 0.04 = 0.8800000000000002 0.8800000000000002 + 0.04 = 0.9200000000000003 0.9200000000000003 + 0.04 = 0.9600000000000003   Why on earth could that happen?!
108487
I have the code below (I've included what I believe are all relevant sections):  private String readCommand = "SELECT LEVEL FROM USERS WHERE VAL_1 = ? AND VAL_@ = ?;"; public bool read(string id) {     level = -1;     MySqlCommand m = new MySqlCommand(readCommand);     m.Parameters.Add(new MySqlParameter("", val1));     m.Parameters.Add(new MySqlParameter("", val2));     MySqlDataReader r = m.ExecuteReader();     if (r.HasRows)         level = Convert.ToInt32(r.GetValue(0).ToString());     r.Close();     return true; }   When I run this, I get an IndexOutOfBoundsException on adding the first parameter. What have I done wrong?
104482
What is the best way to convert an Int value to the corresponding Char in Utf16, given that the Int is in the range of valid values?
57685
I still can't wrap my head around this one and have to consult references every time I want to be safe:   Is it "0.4 point" or "0.4 points"?   Is it "1.0 point" or "1.0 points"?   I know that I can work around that by using four tenths of a point or one point instead, but sometimes writing 0.4 point/points or 1.0 point/points is called for, especially in technical documents.  I gathered that this mostly goes by the style guide I choose to (or have to) use, and it's quite possible that there is no universally accepted convention for this. Then again, in light of potential benefits for learners here, I think it's worth asking, and I hope that we can lay out some rules of thumb, something that can be used as a general guideline, especially on writing tests and exams.  Addendum: another case that's worth mentioning in answers, for completeness, is "0.0 point" or "0.0 points"? In my humble opinion, it's safe to assume that most learners on our site know what to use when the quantity falls out of the range between -1.0 and 1.0.
110598
Do C#/.NET floating point operations differ in precision between debug mode and release mode?
44849
Does anyone know why, using SQLServer 2005  SELECT CONVERT(DECIMAL(30,15),146804871.212533)/CONVERT(DECIMAL (38,9),12499999.9999)   gives me 11.74438969709659,  but when I increase the decimal places on the denominator to 15, I get a less accurate answer:  SELECT CONVERT(DECIMAL(30,15),146804871.212533)/CONVERT(DECIMAL (38,15),12499999.9999)   give me 11.74438969
44298
From the original data, we know that they are nearly 0.087 rather that 0.087 x 10^-2. Why is there scientific notation (10^-2)? It looks ridiculous. Please help me figure it out. Thanks very much!   MWE:  \documentclass[border=5mm]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \definecolor{mycolor1}{rgb}{1,0,1}  \pgfplotstableread{ X           Y1 1    0.0873514639102964  2    0.0873656441069913  3    0.0873509320240032  4    0.0873490368814644  5    0.0873430960617957  6    0.0873334626756388  7    0.0873430596012905  8    0.0873485872405474  9    0.0873519301953318  10  0.0873474824394306 11  0.08735183859007     12  0.0873408783047386 13  0.0873439016123011 14  0.0873424452271129 15  0.0873452848079798 16  0.0873467228778811 17  0.087348210873026    18  0.0873464310394191 19  0.0873469131127228 20  0.0873449430894595 }\datatable  \pgfplotsset{     width=9cm,     height=6cm,     scale only axis,     xmin=0.5, xmax=20.5,     tick align = outside,     yticklabel style={/pgf/number format/fixed},   } \begin{tikzpicture}  \begin{axis}[     xtick={1,...,20},     ymin=0.08715,     ymax=0.08740,     ytick={0.08715,0.08720,0.08725,0.08730,0.08735,0.08740},     yticklabels={0.08715,0.08720,0.08725,0.08730,0.08735,0.08740},     xlabel={$x$},     ylabel={$y$},     y axis line style={mycolor1},     ytick style={mycolor1},     yticklabel style=mycolor1,     yticklabel style={/pgf/number format/fixed},     axis x line*=bottom,     axis y line*=left] \addplot [     color=mycolor1,     solid,     line width=1.5pt,     mark size=2.7pt,     mark=square*,     mark options={solid,fill=mycolor1}]     table [x=X, y=Y1]{\datatable}; \label{plot1} % So we can recall the plot style later on \end{axis} \end{tikzpicture}% \end{document}
85947
How do you write a number with two decimal places for sql server?
33272
There is this example code, but then it starts talking about millisecond / nanosecond problems.  The same question is on MSDN, .  This is what I've got so far:  public Double CreatedEpoch {   get   {     DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime();     TimeSpan span = (this.Created.ToLocalTime() - epoch);     return span.TotalSeconds;   }   set   {     DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime();     this.Created = epoch.AddSeconds(value);   } }
95377
Firstly I do not want to round my numbers, I am using base 10 figures so excel should have no bother doing simple add and subtract.  A|  665.110000000000000000000000000000 B|  4.990000000000000000000000000000 C|  =a1+b1 D|  670.790000000000000000000000000000 E|  1,335.890000000000000000000000000000 F|  =e1-(c1+d1)   I should get -5 however F1  returns   -4.999999999999770000000000000000   It is a financial document therefore I want to avoid rounding, more to the point. Why should I need to? I've put cell formatting to Currency with 2 decimal placed and I will get the correct display value but for all calculations I will still get -4.9999...7 which leads to further errors with conditional formatting etc.