Skip site navigation (1) Skip section navigation (2)

Re: Novice PL/pgSQL question and example

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Novice PL/pgSQL question and example
Date: 2010-02-11 11:31:04
Message-ID: hl0ppo$mjg$1@reversiblemaps.ath.cx (view raw or flat)
Thread:
Lists: pgsql-novice
On 2010-02-08, James Long <pgsql-novice(at)museum(dot)rain(dot)com> wrote:

Newsgroups: gmane.comp.db.postgresql.novice
From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
Subject: Re: Novice PL/pgSQL question and example
References: <20100208013329(dot)GA95096(at)ns(dot)umpquanet(dot)com>
Organization: Dis (not Dat) Organisation
Followup-To: 
X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID(at)6{uf8s;a+M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W;(T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6{T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$(at)f%(dot)kl^:7X8rQWd[NTc"P"u6nkisze/Q;8"9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^

On 2010-02-08, James Long <pgsql-novice(at)museum(dot)rain(dot)com> wrote:
> At least, I hope this is a Novice question.  It sure makes me
> feel like one! :)  Please cc: me directly on replies, as I might
> miss a reply that goes only to the list.
>
> I'm running PostGreSQL 8.3.9 on FreeBSD 6.4-STABLE, but I doubt
> this is platform-dependent.
>
> I'm trying to solve what I'm sure is a common problem in the
> accounting world.  A total cost C has to be split across N
> different accounts, and C is not necessarily divisible by N.
> Shares with fractions of pennies are not allowable, and to make
> the accounting balance, the sum of all the shares has to sum to
> exactly match the total cost C.
>
> It's like splitting a $90 lunch check between 7 people.
>

> This PHP code shows the math I'm using, and works great. 

here's different way to do it.

 share ( pieces , people, index ) = floor (pieces * (index + 1) / people ) - floor ( pieces * index / people) 
  
you don't need to remember an error just increase the index each time.


In response to

pgsql-novice by date

Next:From: Tim LandscheidtDate: 2010-02-11 16:48:25
Subject: Re: Using xpath queries against XML Datatype
Previous:From: Balma Robin GordonDate: 2010-02-11 09:43:26
Subject: Using xpath queries against XML Datatype

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group