function [ d, p ] = r8_to_digits_decimal ( r, n )

%*****************************************************************************80
%
%% r8_to_digits_decimal() returns N decimal digits of R.
%
%  Discussion:
%
%    R = d(1) * 10^p + d(2) * 10^(p-1) + ... + d(n) * 10^(p+1-n) approximately.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 June 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real R: the value to be analyzed.
%
%    integer N: the number of digits to be determined.
%
%  Output:
%
%    integer D(N): the digits.
%
%    integer P: the power of ten.
%
  d = zeros ( n, 1 );
  p = 0;

  if ( r == 0.0 )
    return
  end

  if ( r < 0.0 )
    s = -1.0;
  else
    s = +1.0;
  end

  while ( 10.0 <= r )
    p = p + 1;
    r = r / 10.0;
  end
  while ( r < 1.0 )
    p = p - 1;
    r = r * 10.0;
  end
%
%  Value is now represented by S * R * 10^P, with 1 <= R < 10.
%
  for i = 1 : n
    d(i) = floor ( r );
    r = r - d(i);
    r = r * 10.0;
  end
%
%  Apply the sign.
%
  d = s * d;

  return
end

