numerus/deploy/to_price.sql

34 lines
878 B
MySQL
Raw Permalink Normal View History

-- 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;
sign text := '';
begin
if cents < 0 then
sign := '-';
cents = -cents;
end if;
result = cents::text;
return sign || (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;