title: How to truncate double precision value in PostgreSQL by keeping exactly first two decimals?
body: <p>I'm trying to truncate <strong>double precision</strong> value when I'm build json using <code>json_build_object()</code> function in <strong>PostgreSQL 11.8</strong> but with no luck. To be more precise I'm trying to truncate <strong>19.9899999999999984</strong> number to ONLY two decimals but making sure it DOES NOT round it to 20.00 (which is what it does), but to keep it at <strong>19.98</strong>.</p>
  
  <p>BTW, what I've tried so far was to use:<br/>
  1) <code>TRUNC(found_book.price::numeric, 2)</code> and I get value <strong>20.00</strong><br/>
  2) <code>ROUND(found_book.price::numeric, 2)</code> and I get value <strong>19.99</strong> -> so far this is closesest value but not what I need<br/> 
  3) <code>ROUND(found_book.price::double precision, 2)</code>  and I get </p>
  
  <blockquote>
    <p>[42883] ERROR: function round(double precision, integer) does not exist</p>
  </blockquote>
  
  <p>Also here is whole code I'm using:</p>
  
  <pre><code>create or replace function public.get_book_by_book_id8(b_id bigint) returns json as
  $BODY$
  declare
      found_book book;
      book_authors json;
      book_categories json;
      book_price double precision;
  begin
      -- Load book data:
      select * into found_book
      from book b2
      where b2.book_id  = b_id;
  
      -- Get assigned authors
      select case when count(x) = 0 then '[]' else json_agg(x) end into book_authors
      from (select aut.*
          from book b
          inner join author_book as ab on b.book_id = ab.book_id
          inner join author as aut on ab.author_id = aut.author_id
          where b.book_id = b_id) x;
  
      -- Get assigned categories
      select case when count(y) = 0 then '[]' else json_agg(y) end into book_categories
      from (select cat.*
          from book b
          inner join category_book as cb on b.book_id = cb.book_id
          inner join category as cat on cb.category_id = cat.category_id
          where b.book_id = b_id) y;
  
      book_price = trunc(found_book.price, 2);
      -- Build the JSON response:
      return (select json_build_object(
          'book_id', found_book.book_id,
          'title', found_book.title,
          'price', book_price,
          'amount', found_book.amount,
          'is_deleted', found_book.is_deleted,
          'authors', book_authors,
          'categories', book_categories
      ));
  end
  $BODY$
  language 'plpgsql';
  
  select get_book_by_book_id8(186);
  </code></pre>
  
  <p>How do I achieve to keep EXACTLY ONLY two FIRST decimal digits 19.<strong>98</strong> (any suggestion/help is greatly appreciated)?</p>
  
  <p><strong>P.S.</strong> PostgreSQL version is 11.8</p>