-- Deploy numerus:to_price to pg
-- requires: schema_numerus

begin;

set search_path to numerus, public;

create or replace function to_price(cents integer, decimal_digits integer) returns text as
$$
declare
	result text;
	scale integer := 10^decimal_digits;
begin
	result = cents::text;
	return (cents / scale)::text || '.' || to_char(mod(cents, scale), rpad('FM', decimal_digits + 2, '0'));
end;
$$
language plpgsql
immutable;

comment on function to_price(integer, integer) is
'Converts the cents to a price representation, without currency and any other separater than decimal.';

revoke execute on function to_price(integer, integer) from public;
grant execute on function to_price(integer, integer) to invoicer;
grant execute on function to_price(integer, integer) to admin;

commit;
