Ho scritto un programma su visual c# che fa la differenza di 2 numeri ed ho ottenuto il seguente risultato:
9 - 8.9 = 0,0999999999999996
Sarebbe questa la precisione di visual c#?!?!![]()
Qui sotto trovate il codice:
codice: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 WindowsFormsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void calcola_Click(object sender, EventArgs e) { double Variabile_A = double.Parse(A.Text); double Variabile_B = double.Parse(B.Text); double Variabile_C; if (n.Text == "+") Variabile_C = Variabile_A + Variabile_B; else Variabile_C = Variabile_A - Variabile_B; C.Text = Convert.ToString(Variabile_C); } private void S1_CheckedChanged(object sender, EventArgs e) { if (S1.Checked) n.Text = "+"; else n.Text = "-"; } private void S2_CheckedChanged(object sender, EventArgs e) { if (S1.Checked) n.Text = "+"; else n.Text = "-"; } private void n_TextChanged(object sender, EventArgs e) { } private void C_TextChanged(object sender, EventArgs e) { } } }
Questo C mi convince sempre meno...![]()


Rispondi quotando
