This is my code –
private void button1_Click(object sender, EventArgs e)
{
double number =Convert.ToDouble( textBox1.Text);
string s = (Math.Round(number, 3)*1000).ToString();
int norm=1;
for(int i=0;i<=s.Length-1;i++)
{
norm*=10;
}
label1.Text =Math.Round((Convert.ToDouble(s)/norm),3).ToString() ;
}
This should actually bring a number like 21234,34532 to 2,123 or 75898331 to 7,589(theorethicaly) and so on.
When I tried on 75898331 it gave me an unexpected result of (24.328). Can someone tell me where I messed up? Double isn’t enough to work with such big number.
No it didn’t. When I tried the same,
It gave s as “75898331000”
So you are trying to create an int (32 bits) which overflows.
Try making
norman Int64 instead.