var Unit = {};

Unit.labels = { ohms : '\u2126', kilo_ohms : 'k\u2126', mega_ohms : 'M\u2126' };

Unit.normalizeToOhms = function(value, unit) {
    switch (unit) {
    case Unit.labels.ohms:
        return value;
    case Unit.labels.kilo_ohms:
        return value * 1000;
    case Unit.labels.mega_ohms:
        return value * 1e6;
    }
    return null;
};
    
Unit.ohmCompatible = function(unit) {
    if (unit == Unit.labels.ohms || unit == Unit.labels.kilo_ohms ||
        unit == Unit.labels.mega_ohms)
    {
        return true;
    }
    return false;
};

// Return a string with a unit representing the resistance value.
// value: resistance value in ohms
Unit.res_str = function(value) {
    var vstr;
    var unit;
    
    if (value < 1000) {
        vstr = String(value);
        unit = Unit.labels.ohms;
    }
    else {
        vstr = String(value / 1000.0);
        unit = Unit.labels.kilo_ohms;
    }
    
    /*
    var n = vstr.match('.') ?  4 : 3;
    if (vstr.charAt(0) == '1') { ++n; }
    if (vstr.length > n) {
        vstr = vstr.substring(0, n);
    }
    */
    vstr = vstr.replace(/(\.[0-9]*[1-9])0000000*[1-9]/, '$1')
    return vstr + ' ' + unit;
};

Unit.res_unit_str = function(value, mult) {
    var vstr;
    var unit = Unit.labels.ohms;
    
    if (mult === 'k') {
        vstr = String(value / 1000.0);
        unit = Unit.labels.kilo_ohms;
    }
    else if (mult === 'M') {
        vstr = String(value / 1000000.0);
        unit = Unit.labels.mega_ohms;
    }
    else {
        vstr = String(value);
        unit = Unit.labels.ohms;
    }
    return vstr + ' ' + unit;
};

Unit.pct_str = function(value) {
    return (value * 100) + ' %';
};


@@ -836,37 +836,33 @@
  %7B%0A        v
-str = String(
+ar val = 
 value / 1000
@@ -855,32 +855,130 @@
 = value / 1000.0
+;%0A        if (val.toFixed) %7B%0A            val = val.toFixed(6);%0A        %7D%0A        vstr = String(val
 );%0A        unit 
@@ -1179,70 +1179,8 @@
  */%0A
-    vstr = vstr.replace(/(%5C.%5B0-9%5D*%5B1-9%5D)0000000*%5B1-9%5D/, '$1')%0A
     

Apply toFixed before converting the num to string