I want to change this code to C# code here val is a double value
function round7(val)
define v1,v2
v1=val
if abs(v1)>0
v2=int(log(abs(v1)))
v1=v1/(10^v2)
v1=round(v1,6)
v1=v1*10^v2
end if
return v1
end function
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jul 8, 2014, 7:43 AM
So, I think you do need to work to significant figures rather than decimal places. Try instead:
// current method code
Farhan ShariffPosted Jul 8, 2014, 8:06 AM
Farhan ShariffPosted Jul 8, 2014, 7:35 AM
for instance :
Before using the code
http://i.imgur.com/qJXgYEG.png
After using the code
http://i.imgur.com/dlZ6Ech.png
Anyways I will use this
Output from this is Acceptable
Thanks once again
public static double Round7(double val)
{
double v1, v2;
v1 = val;
if(Math.Abs(v1) > 0)
{
v2 = (int)(Math.Log10(Math.Abs(v1)));
v1 = v1 / Math.Pow(10, v2);
v1 = Math.Round(v1, 6);
v1 = v1 * Math.Pow(10, v2);
}
return v1;
}
VulpesPosted Jul 8, 2014, 7:14 AM
Farhan ShariffPosted Jul 8, 2014, 6:56 AM
{
string colx = delta_table.Columns[g1].ToString();
string minx = delta_table.Rows[0][colx].ToString();
int maxat = delta_table.Rows.Count-1;
string maxx = delta_table.Rows[maxat][colx].ToString();
double lower = double.Parse(table1.Rows[g1]["Delta_Lower_Limit"].ToString());
double upper = double.Parse(table1.Rows[g1]["Delta_Upper_Limit"].ToString());
double v1_lower, v2_lower;
v1_lower = lower;
if (Math.Abs(v1_lower) > 0)
{
v2_lower = (int)(Math.Log10(Math.Abs(v1_lower)));
v1_lower = v1_lower / Math.Pow(10, v2_lower);
v1_lower = Math.Round(v1_lower, 6);
v1_lower = v1_lower * Math.Pow(10, v2_lower);
}
double v1_upper, v2_upper;
v1_upper = upper;
if (Math.Abs(v1_upper) > 0)
{
v2_upper = (int)(Math.Log10(Math.Abs(v1_upper)));
v1_upper = v1_upper / Math.Pow(10, v2_upper);
v1_upper = Math.Round(v1_upper, 6);
v1_upper = v1_upper * Math.Pow(10, v2_upper);
}
double minxv = Convert.ToDouble(minx) + 2*lower;
double maxxv = Convert.ToDouble(maxx) + 2*upper;
v1 = minxv;
if (Math.Abs(v1) > 0)
{
v2 = (int)(Math.Log10(Math.Abs(v1)));
v1 = v1 / Math.Pow(10, v2);
v1 = Math.Round(v1, 6);
v1= v1*Math.Pow(10,v2);
}
double v1_1, v2_1;
v1_1 = maxxv;
if (Math.Abs(v1_1) > 0)
{
v2_1 = (int)(Math.Log10(Math.Abs(v1_1)));
v1_1 = v1_1 / Math.Pow(10, v2_1);
v1_1 = Math.Round(v1_1, 6);
v1_1 = v1_1 * Math.Pow(10, v2_1);
}
chart1.ChartAreas[0].AxisX.Minimum = v1;
chart1.ChartAreas[0].AxisX.Maximum = v1_1;
}
VulpesPosted Jul 8, 2014, 6:55 AM
Farhan ShariffPosted Jul 8, 2014, 6:53 AM
VulpesPosted Jul 8, 2014, 6:52 AM
Farhan ShariffPosted Jul 8, 2014, 6:49 AM
I thought If I set Min and Max values of the x axis it should work
but only first value that is Minimum is rounded off to 6 places but rest are not
http://i.imgur.com/6Q3PgbE.png
VulpesPosted Jul 8, 2014, 6:48 AM
public static double Round7(double val)
{
double v1, v2;
v1 = val;
if(Math.Abs(v1) > 0)
{
v2 = (int)(Math.Log10(Math.Abs(v1)));
v1 = v1 / Math.Pow(10, v2);
v1 = Math.Round(v1, 6);
v1 = v1 * Math.Pow(10, v2);
}
return v1;
}
VulpesPosted Jul 8, 2014, 6:37 AM
public static double Round7(double val)
{
double v1, v2;
v1 = val;
if(Math.Abs(v1) > 0)
{
v2 = (int)(Math.Log(Math.Abs(v1)));
v1 = v1 / Math.Pow(10, v2);
v1 = Math.Round(v1, 6);
v1 = v1 * Math.Pow(10, v2);
}
return v1;
}
I've assumed that the log function is base e rather than base 10.