anchor.diff:  %% Internal functions
   %% ====================================================================
   
  +
  +% 
  +% Check if if value fits into the display
   %
  -% Format the input number given the number of digits and desired precision
  -%
  --spec format_number(InValue :: float(),
  -                    NumOfDigits :: integer(),
  -                    Inputs :: input_attribs()) -> 
  -                       {ok, list(byte()), integer()} | {error, too_big | input_errors(), boolean()}.
  -
  -format_number(InValue, NumOfDigits, Inputs) ->
  -
  -  if ((-1.0 < InValue) andalso (InValue < 1.0)) ->
  -    IsLessThanOne = true;
  -  true ->
  -    IsLessThanOne = false
  -  end,
  -
  -  if (InValue >= 0.0) ->
  -    % Max precision is NumOfDigits-1, for leading zero
  -    PrecResult = input_utils:get_integer_range(Inputs, pos_precision, 0, 
  -                                               (NumOfDigits-1)),
  -    IsNegative = false; 
  -  true ->
  -    % Max precision is NumOfDigits-2, for minus sign and leading zero
  -    PrecResult = input_utils:get_integer_range(Inputs, neg_precision, 0, 
  -                                               (NumOfDigits-2)),
  -    IsNegative = true 
  -  end,
  -
  -  case PrecResult of
  -    {ok, null} ->
  -      % Don't care about precision 
  -      % Format number with the maximum possible precision
  -      if IsNegative ->
  -        MaxPrecision = NumOfDigits - 2;
  -      true ->
  -        MaxPrecision = NumOfDigits - 1
  -      end,
  -      
  -      max_precision(InValue, NumOfDigits, MaxPrecision, IsNegative, IsLessThanOne);
  -
  -    {ok, Precision} ->
  -      DigitsToDisp = digits_to_display(InValue, Precision, IsNegative, IsLessThanOne),
  -      
  -      if (length(DigitsToDisp) > NumOfDigits) ->
  -        {error, too_big, IsNegative};
  -      true ->
  -        {ok, DigitsToDisp, Precision}
  -      end;
  -
  -    {error, Reason} -> {error, Reason, false}
  -  end.
  -
  -
  -%
  -% Find the maximum precision that fits in the number of digits allowed
  -% Starting precision is NumOfDigits -1 or -2 (for negative numbers)
  -%
  --spec max_precision(InValue :: float(),
  -                    NumOfDigits :: pos_integer(),
  -                    Precision :: non_neg_integer(),
  -                    IsNegative :: boolean(),
  -                    IsLessThanOne :: boolean()) -> {ok, list(), pos_integer()} |
  -                                                   {error, too_big, boolean()}. 
  -
  -max_precision(InValue, NumOfDigits, 0, IsNegative, IsLessThanOne) ->
  -  DigitsToDisp = 
  -    digits_to_display(InValue, 0, IsNegative, IsLessThanOne),
  -
  -  if (length(DigitsToDisp) > NumOfDigits) ->
  -    % Number doesn't fit using least (zero) precision, return error
  -    {error, too_big, IsNegative};
  -  true ->
  -    {ok, DigitsToDisp, 0}
  -  end;
  -
  -max_precision(InValue, NumOfDigits, Precision, IsNegative, IsLessThanOne) ->
  -  DigitsToDisp = digits_to_display(InValue, Precision, 
  -                                    IsNegative, IsLessThanOne),
  -
  -  if (length(DigitsToDisp) > NumOfDigits) ->
  -    % Number doesn't fit, try formatting at a lower precision
  -    max_precision(InValue, NumOfDigits, Precision-1, 
  -                  IsNegative, IsLessThanOne);
  -
  -  true ->
  -    % Number fits in the display, use this.
  -    {ok, DigitsToDisp, Precision}
  -  end.
  -
  -
  -%
  -% Get the list of digits to display, without a decimal point
  -% Add the minus sign and leading zero where appropriate
  -%
  --spec digits_to_display(InValue :: float(),
  -                        Precision :: non_neg_integer(),
  -                        IsNegative :: boolean(),
  -                        IsLessThanOne :: boolean()) -> list().
  -
  -digits_to_display(InValue, Precision, IsNegative, IsLessThanOne) ->
  -  % Example: 
  -  %   InValue 12.3456, Precision 3
  -  %   InValueNoDecPnt = 12346
  -  InValueNoDecPnt = round(math:pow(10, Precision) * InValue),
  -
  -  RawDigits = integer_to_list(InValueNoDecPnt, 10),
  -
  -  if IsLessThanOne ->
  -    % Add leading zero
  -    if IsNegative ->
  -      % Add minus sign
  -      [$- | [$0 | RawDigits]];
  -    true ->
  -      [$0 | RawDigits]
  -    end;
  -  true -> 
  -    if IsNegative ->
  -      [$- | RawDigits];
  -    true ->
  -      RawDigits
  -    end
  +-spec check_length(InValueStr :: string(),
  +                   NumOfDigits :: integer()) -> boolean().
  +
  +check_length(InValueStr, NumOfDigits) ->
  +
  +  case lists:member($., InValueStr) of
  +    true -> % don't count decimal point when determining if digits fit into display
  +      length(InValueStr) =< (NumOfDigits + 1);
  +
  +    false -> % No decimal point in string
  +      length(InValueStr) =< NumOfDigits
     end.
   
   
  
positive.code: 
  initialize({Config, Inputs, Outputs, Private}) ->
    % Check the config values
    case config_utils:get_integer_range(Config, num_of_digits, 2, 99) of
      {ok, NumOfDigits} ->
        % Create a digit output for each digit
        Outputs1 = output_utils:resize_attribute_array_value(Outputs, 
                                         digits, NumOfDigits, {null, []}),
        Value = null,
        Status = initialed;
  
      {error, Reason} ->
        Outputs1 = Outputs,
        {Value, Status} = config_utils:log_error(Config, num_of_digits, Reason)          
    end,
  
    Outputs2 = output_utils:set_value_status(Outputs1, Value, Status),
  
negative.code:   attrib_utils:merge_attribute_lists(
      block_common:configs(BlockName, ?MODULE, version(), Description), 
      [
        {num_of_digits, {4}}, %| int | 4 | 1..99 |
        {pos_precision, {2}}, %| int | 2 | 0..num of digits |
        {neg_precision, {1}} %| int | 1 | 1..num of digits |
      ]). 
  
  
  