title: Elegant PL/SQL to compare two numbers with different amount of decimal places
body: <p>I need a function to compare two numbers so that <code>10.12432 = 10.124</code> and <code>10.12432 != 10.123</code>. That is the more accurate number needs to be rounded according to the decimal places of the less accurate one.</p>
  
  <p>The following function seems to do what I need (<strong>Edited</strong> as per Noel's comment):</p>
  
  <pre><code>function eq(number_1 in number, number_2 in number) return boolean is
      string_1 varchar2(100); 
      string_2 varchar2(100); 
  
      num_1    number;
      num_2    number;
  
      len      number;
  begin
      string_1 := to_char(number_1, 'FM99999999999999999999999999999.99999999999999999999999999999');
      string_2 := to_char(number_2, 'FM99999999999999999999999999999.99999999999999999999999999999');
  
      string_1 := regexp_replace(string_1, '.*(\..*)', '\1');
      string_2 := regexp_replace(string_2, '.*(\..*)', '\1');
  
      len   := least(length(string_1), length(string_2)) - 1;
  
      num_1 := round(number_1, len);
      num_2 := round(number_2, len);
  
      return num_1 = num_2;
  
  end eq;
  </code></pre>
  
  <p>But, imho, is not the most satisfying approach. Is there a better solution, notably one without resorting to strings?</p>