Get rid of Global class, discussion

Nov 11, 2013 at 9:32 PM
Edited Nov 11, 2013 at 9:33 PM
I just looked at Global class which contains an array of scale top values. I think, it would be better (or not) to move this class to method in this way:
public static double GetGaugeTop(string Value) {
    double temp;
    if (Value[0] == '-') {
        Value = (Math.Floor(Convert.ToDouble(Value))).ToString();
        temp = Convert.ToDouble(Math.Pow(10, Value.Length - 1));
        if (Int32.Parse(Value[1].ToString()) < 5) {
            temp = temp / 2;
        }
        return temp;
    }
    Value = (Math.Ceiling(Convert.ToDouble(Value))).ToString();
    temp = Convert.ToDouble(Math.Pow(10, Value.Length));
    if (Int32.Parse(Value[0].ToString()) < 5) {
        temp = temp / 2;
    }
    return temp;
}
We just take the numerical string, round it. If the number is positive, round to greater integer, if number is negative, to lower. Then calculate powers and, finally, compare whether the number is greater lower than a half of calculated powers and divide by two if necessary.

It is just quick code, maybe it can be significantly simplified. The biggest advantage is that everything is calculated automatically. Just a thought.
Nov 12, 2013 at 11:17 AM
I just checked the code again and decided that it is a bad idea. Fixed scale table isn't that simple and offers scale management. Please, ignore this thread.