code: public static TermLengthOrPercent createLengthOrPercent(String spec)
      {
          spec = spec.trim();
          if (spec.endsWith("%"))
          {
              try {
                  float val = Float.parseFloat(spec.substring(0, spec.length() - 1));
                  TermPercent perc = CSSFactory.getTermFactory().createPercent(val);
                  return perc;
              } catch (NumberFormatException e) {
                  return null;
              }
          }
          else
          {
              try {
                  float val = Float.parseFloat(spec);
                  TermLength len = CSSFactory.getTermFactory().createLength(val, TermLength.Unit.px);
                  return len;
              } catch (NumberFormatException e) {
                  return null;
              }
          }
      }
docs: Creates a CSS length or percentage from a string.
  @param spec The string length or percentage according to CSS
  @return the length or percentage